fix(memory): file the cache-hit result before running its callback

Restores the original ordering. Releasing the payload after the callback
meant filing the result after it too, so a callback that queried
get_result() or is_request_complete() for its own request would not have
found it -- a behaviour change unrelated to the memory fix.

The dict holds a reference to the same object, so releasing after filing
still clears the payload.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Chuck
2026-08-23 14:28:09 -04:00
co-authored by Claude Opus 5
parent ff8d0b01a6
commit c856baf7ef
+6 -2
View File
@@ -199,6 +199,12 @@ class BackgroundDataService:
cached=True,
fetch_time=0.0
)
# Filed before the callback runs, as it always was: a callback
# that queries get_result()/is_request_complete() for its own
# request must still find it. Releasing afterwards mutates the
# same object the dict holds.
self.completed_requests[request_id] = result
if callback:
try:
callback(result)
@@ -206,8 +212,6 @@ class BackgroundDataService:
logger.error(f"Error in callback for request {request_id}: {e}")
self._release_payload(result)
self.completed_requests[request_id] = result
logger.debug(f"Cache hit for {sport} {year} data")
return request_id