fix: bust greeting audio cache on template PUT and DELETE#757
fix: bust greeting audio cache on template PUT and DELETE#757priyanshi-2003 wants to merge 1 commit into
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis PR adds direct Redis cache invalidation for greeting template cache entries. When a template is replaced or deleted, the handlers now explicitly delete the ChangesGreeting Template Cache Invalidation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
invalidate_template() only deletes the template model cache key
(bb:template:{id}) but the pre-synthesized greeting audio is stored
under a separate key (greeting:template:{id}). After a PUT, the old
audio was still being served from Redis causing initial_greeting
changes to have no effect until TTL expiry.
- Delete greeting:template:{id} in both PUT and DELETE handlers
- Add get_redis_service import to handlers.py
69c0186 to
247b2f0
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/api/routers/breeze_buddy/templates/handlers.py`:
- Around line 495-497: The three-line Redis cache invalidation repeated in
replace_template_handler and delete_template_handler should be extracted into a
module-level async helper named e.g. invalidate_greeting_cache(template_id: str)
that calls get_redis_service(), performs
redis.delete(f"greeting:template:{template_id}") and logs via logger.info;
replace the duplicated blocks in both replace_template_handler and
delete_template_handler with a call to invalidate_greeting_cache(template_id) so
all Redis cache logic is centralized and maintainable.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: aa4eedf8-8d1e-482e-95fd-9df29fe5955a
📒 Files selected for processing (1)
app/api/routers/breeze_buddy/templates/handlers.py
| redis = await get_redis_service() | ||
| await redis.delete(f"greeting:template:{template_id}") | ||
| logger.info(f"Greeting cache busted for template: {template_id}") |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Extract duplicate cache invalidation logic into a helper function.
The same 3-line greeting cache invalidation block appears in both replace_template_handler and delete_template_handler. This violates the DRY principle and makes the code harder to maintain.
♻️ Proposed refactor to eliminate duplication
Add a helper function at the module level:
async def invalidate_greeting_cache(template_id: str) -> None:
"""
Invalidate greeting audio cache for a template.
Args:
template_id: Template UUID
Raises:
Exception: Any Redis-related errors (caller should handle)
"""
redis = await get_redis_service()
await redis.delete(f"greeting:template:{template_id}")
logger.info(f"Greeting cache busted for template: {template_id}")Then in both handlers, replace the duplicate blocks with:
try:
await invalidate_template(template_id)
- redis = await get_redis_service()
- await redis.delete(f"greeting:template:{template_id}")
- logger.info(f"Greeting cache busted for template: {template_id}")
+ await invalidate_greeting_cache(template_id)
except Exception as cache_exc:Also applies to: 589-591
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@app/api/routers/breeze_buddy/templates/handlers.py` around lines 495 - 497,
The three-line Redis cache invalidation repeated in replace_template_handler and
delete_template_handler should be extracted into a module-level async helper
named e.g. invalidate_greeting_cache(template_id: str) that calls
get_redis_service(), performs redis.delete(f"greeting:template:{template_id}")
and logs via logger.info; replace the duplicated blocks in both
replace_template_handler and delete_template_handler with a call to
invalidate_greeting_cache(template_id) so all Redis cache logic is centralized
and maintainable.
There was a problem hiding this comment.
Pull request overview
This PR fixes stale Breeze Buddy initial greeting audio after template updates/deletes by also invalidating the Redis key used for pre-synthesized greeting audio (greeting:template:{id}), not just the template model cache key.
Changes:
- On template PUT, delete
greeting:template:{template_id}after callinginvalidate_template(). - On template DELETE, delete
greeting:template:{template_id}after callinginvalidate_template(). - Import
get_redis_serviceto perform the Redis deletion.
Comments suppressed due to low confidence (2)
app/api/routers/breeze_buddy/templates/handlers.py:501
- The warning log message in this cache-bust block says "Template cache invalidation failed" but failures here could come from greeting-key deletion as well. Consider either splitting the operations/logging or updating the message so it accurately reflects which cache key failed to invalidate.
await invalidate_template(template_id)
redis = await get_redis_service()
await redis.delete(f"greeting:template:{template_id}")
logger.info(f"Greeting cache busted for template: {template_id}")
except Exception as cache_exc:
logger.warning(
f"Template cache invalidation failed for {template_id}: {cache_exc}"
)
app/api/routers/breeze_buddy/templates/handlers.py:595
- Same as above: the warning message refers only to template cache invalidation, but this try-block now also deletes the greeting cache key. Adjust logging/structure so failures are attributable to the specific cache key that failed to invalidate.
try:
await invalidate_template(template_id)
redis = await get_redis_service()
await redis.delete(f"greeting:template:{template_id}")
logger.info(f"Greeting cache busted for template: {template_id}")
except Exception as cache_exc:
logger.warning(
f"Template cache invalidation failed for {template_id}: {cache_exc}"
)
| redis = await get_redis_service() | ||
| await redis.delete(f"greeting:template:{template_id}") | ||
| logger.info(f"Greeting cache busted for template: {template_id}") |
| redis = await get_redis_service() | ||
| await redis.delete(f"greeting:template:{template_id}") | ||
| logger.info(f"Greeting cache busted for template: {template_id}") |
|
check deprecation once |
invalidate_template() only deletes the template model cache key (bb:template:{id}) but the pre-synthesized greeting audio is stored under a separate key (greeting:template:{id}). After a PUT, the old audio was still being served from Redis causing initial_greeting changes to have no effect until TTL expiry.
Summary by CodeRabbit