@@ -40,7 +40,7 @@ def extract_cohort_dependencies(cohort: Cohort) -> set[int]:
4040 return dependencies
4141
4242
43- def get_cohort_dependencies (cohort : Cohort ) -> list [int ]:
43+ def get_cohort_dependencies (cohort : Cohort , _warming : bool = False ) -> list [int ]:
4444 """
4545 Get the list of cohort IDs that the given cohort depends on.
4646 """
@@ -50,10 +50,11 @@ def get_cohort_dependencies(cohort: Cohort) -> list[int]:
5050 cache_hit = cache .has_key (cache_key )
5151
5252 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 ()
5455 return list (extract_cohort_dependencies (cohort ))
5556
56- if cache_hit :
57+ if cache_hit and not _warming :
5758 COHORT_DEPENDENCY_CACHE_COUNTER .labels (cache_type = "dependencies" , result = "hit" ).inc ()
5859
5960 result = cache .get_or_set (
@@ -114,7 +115,7 @@ def warm_team_cohort_dependency_cache(team_id: int, batch_size: int = 1000):
114115 for cohort in Cohort .objects .filter (team_id = team_id , deleted = False ).iterator (chunk_size = batch_size ):
115116 # Any invalidated dependencies cache is rebuilt here
116117 dependents_map .setdefault (_cohort_dependents_key (cohort .id ), [])
117- dependencies = get_cohort_dependencies (cohort )
118+ dependencies = get_cohort_dependencies (cohort , _warming = True )
118119 # Dependency keys aren't fully invalidated; make sure they don't expire.
119120 cache .touch (_cohort_dependencies_key (cohort .id ), timeout = DEPENDENCY_CACHE_TIMEOUT )
120121 # Build reverse map
0 commit comments