@@ -40,7 +40,7 @@ def extract_cohort_dependencies(cohort: Cohort) -> set[int]:
40
40
return dependencies
41
41
42
42
43
- def get_cohort_dependencies (cohort : Cohort ) -> list [int ]:
43
+ def get_cohort_dependencies (cohort : Cohort , _warming : bool = False ) -> list [int ]:
44
44
"""
45
45
Get the list of cohort IDs that the given cohort depends on.
46
46
"""
@@ -50,10 +50,11 @@ def get_cohort_dependencies(cohort: Cohort) -> list[int]:
50
50
cache_hit = cache .has_key (cache_key )
51
51
52
52
def compute_dependencies ():
53
- COHORT_DEPENDENCY_CACHE_COUNTER .labels (cache_type = "dependencies" , result = "miss" ).inc ()
53
+ if not _warming :
54
+ COHORT_DEPENDENCY_CACHE_COUNTER .labels (cache_type = "dependencies" , result = "miss" ).inc ()
54
55
return list (extract_cohort_dependencies (cohort ))
55
56
56
- if cache_hit :
57
+ if cache_hit and not _warming :
57
58
COHORT_DEPENDENCY_CACHE_COUNTER .labels (cache_type = "dependencies" , result = "hit" ).inc ()
58
59
59
60
result = cache .get_or_set (
@@ -114,7 +115,7 @@ def warm_team_cohort_dependency_cache(team_id: int, batch_size: int = 1000):
114
115
for cohort in Cohort .objects .filter (team_id = team_id , deleted = False ).iterator (chunk_size = batch_size ):
115
116
# Any invalidated dependencies cache is rebuilt here
116
117
dependents_map .setdefault (_cohort_dependents_key (cohort .id ), [])
117
- dependencies = get_cohort_dependencies (cohort )
118
+ dependencies = get_cohort_dependencies (cohort , _warming = True )
118
119
# Dependency keys aren't fully invalidated; make sure they don't expire.
119
120
cache .touch (_cohort_dependencies_key (cohort .id ), timeout = DEPENDENCY_CACHE_TIMEOUT )
120
121
# Build reverse map
0 commit comments