fix(api): keep callback summary cache key stable
This commit is contained in:
@@ -328,7 +328,7 @@ async def list_callback_replies(
|
||||
"per_page": per_page,
|
||||
}
|
||||
|
||||
cache_key = {
|
||||
callback_summary_cache_key = {
|
||||
"project_id": project_id or "__all__",
|
||||
"callback_reply_status": callback_reply_status or "",
|
||||
"action": callback_action or "",
|
||||
@@ -339,7 +339,7 @@ async def list_callback_replies(
|
||||
if not refresh:
|
||||
cached_response = await get_cached_operator_summary_async(
|
||||
"callback_replies",
|
||||
cache_key,
|
||||
callback_summary_cache_key,
|
||||
ttl_seconds=_CALLBACK_REPLY_CACHE_TTL_SECONDS,
|
||||
)
|
||||
if cached_response is not None:
|
||||
@@ -468,8 +468,8 @@ async def list_callback_replies(
|
||||
)
|
||||
continue
|
||||
incident_id = str(incident)
|
||||
cache_key = (item_project_id, incident_id)
|
||||
cached = status_chain_cache.get(cache_key)
|
||||
status_chain_cache_key = (item_project_id, incident_id)
|
||||
cached = status_chain_cache.get(status_chain_cache_key)
|
||||
if cached is not None:
|
||||
item["awooop_status_chain"] = cached
|
||||
else:
|
||||
@@ -482,18 +482,18 @@ async def list_callback_replies(
|
||||
project_id=item_project_id,
|
||||
remediation_history=remediation_history,
|
||||
)
|
||||
status_chain_cache[cache_key] = chain
|
||||
status_chain_cache[status_chain_cache_key] = chain
|
||||
item["awooop_status_chain"] = chain
|
||||
|
||||
summary_cache_key = (item_project_id, incident_id)
|
||||
km_summary = km_completion_summary_cache.get(summary_cache_key)
|
||||
km_summary_cache_key = (item_project_id, incident_id)
|
||||
km_summary = km_completion_summary_cache.get(km_summary_cache_key)
|
||||
if km_summary is None:
|
||||
km_summary = await _fetch_km_stale_completion_summary_for_incident(
|
||||
project_id=item_project_id,
|
||||
incident_id=incident_id,
|
||||
queue_cache=km_completion_queue_cache,
|
||||
)
|
||||
km_completion_summary_cache[summary_cache_key] = km_summary
|
||||
km_completion_summary_cache[km_summary_cache_key] = km_summary
|
||||
item["km_stale_completion_summary"] = km_summary
|
||||
|
||||
response = {
|
||||
@@ -517,7 +517,7 @@ async def list_callback_replies(
|
||||
)
|
||||
return await store_operator_summary_async(
|
||||
"callback_replies",
|
||||
cache_key,
|
||||
callback_summary_cache_key,
|
||||
response,
|
||||
ttl_seconds=_CALLBACK_REPLY_CACHE_TTL_SECONDS,
|
||||
)
|
||||
|
||||
@@ -816,6 +816,21 @@ def test_list_callback_replies_keeps_audit_summary_separate_from_km_summary() ->
|
||||
assert 'item["km_stale_completion_summary"] = km_summary' in source
|
||||
|
||||
|
||||
def test_list_callback_replies_does_not_shadow_summary_cache_key() -> None:
|
||||
source = inspect.getsource(platform_operator_service.list_callback_replies)
|
||||
|
||||
assert "callback_summary_cache_key = {" in source
|
||||
assert "status_chain_cache_key = (item_project_id, incident_id)" in source
|
||||
assert "km_summary_cache_key = (item_project_id, incident_id)" in source
|
||||
assert (
|
||||
'store_operator_summary_async(\n "callback_replies",\n'
|
||||
" callback_summary_cache_key"
|
||||
) in source
|
||||
assert not any(
|
||||
line.strip().startswith("summary_cache_key =") for line in source.splitlines()
|
||||
)
|
||||
|
||||
|
||||
def test_callback_reply_audit_summary_marks_missing_snapshots() -> None:
|
||||
summary = _callback_reply_audit_summary_from_row(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user