Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Sep 18, 2023
1 parent 6199feb commit 1b943cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions posthog/caching/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Any, List, Optional, Set, Tuple, Union
from typing import Any, Dict, List, Optional, Set, Tuple, Union
from zoneinfo import ZoneInfo

from dateutil.parser import parser
Expand Down Expand Up @@ -96,7 +96,9 @@ def is_stale(team: Team, date_to: datetime, interval: str, cached_result: Any) -
if stale_cache_invalidation_disabled(team):
return False

last_refresh = cached_result.get("last_refresh", None)
last_refresh = (
cached_result.get("last_refresh", None) if isinstance(cached_result, Dict) else cached_result.last_refresh
)
date_to = min([date_to, datetime.now(tz=ZoneInfo("UTC"))]) # can't be later than now

if last_refresh is None:
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql_queries/query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def run_cached(self, refresh_requested: bool) -> InsightQueryNode:

if cached_result_package and cached_result_package.result:
if not self.is_stale(cached_result_package):
cached_result_package["is_cached"] = True
cached_result_package.is_cached = True
QUERY_CACHE_HIT_COUNTER.labels(team_id=self.team.pk, cache_hit="hit").inc()
return cached_result_package
else:
Expand Down

0 comments on commit 1b943cb

Please sign in to comment.