fix: invalidate cache after PlayerService write operations (#32) #47
No reviewers
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-database#47
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/major-domo-database-32"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
PlayerServicedefinedcache_patternsbut never used them after write operationsfinally:blocks toupdate_player,patch_player,create_players, anddelete_playerthat calltemp_service.invalidate_related_cache(cls.cache_patterns)TeamServiceFiles Changed
app/services/player_service.py— 4finally:blocks added to write methodsHow It Works
cache_patterns = ["players*", "players-search*", "player*", "team-roster*"]covers all GET endpoint cache keys (keyed bykey_prefixin@cache_result). Thefinally:block ensures invalidation runs even if the write operation raises an exception.Other Observations
TeamServicewrite methods also calltemp_service.close_db()in theirfinally:blocks;PlayerServicewrite methods do not. This inconsistency is pre-existing and out of scope for this issue.player_service.py(Peewee model attribute access, protocol mismatches) — all pre-existing and unrelated to this fix.AI Code Review
Files Reviewed
app/services/player_service.py(modified)Findings
Correctness
finally:blocks are correctly placed after their respectiveexceptblocks and calltemp_service.invalidate_related_cache(cls.cache_patterns)— matching theTeamServicepattern exactly.temp_serviceis defined before eachtry/finally, so it is always in scope when thefinallyblock runs.require_auth(token)occur before thetryblock, so unauthorized requests do not trigger cache invalidation — correct behaviour.TeamService.invalidate_related_cachegracefully handles a missing Redis connection (falls back toMockCacheServiceviabase.py).cache_patternslist covers all relevant GET key prefixes:players*,players-search*,player*,team-roster*.Security
Style & Conventions
TeamServicecallsclose_db()infinally,PlayerServicedoes not) is correctly identified as out of scope.Suggestions
close_db()gap versusTeamServicecould be addressed in a follow-up if connection exhaustion becomes a concern under load.Verdict: APPROVED
Straightforward and correct. The fix closes the gap between
cache_patternsbeing declared and never used, alignsPlayerServicewithTeamService's established invalidation pattern, and thefinallyplacement is safe in all execution paths.Automated review by Claude PR Reviewer