Bladeren bron

cloud_functions: don't add today's totals to warm cache

Don't add today's totals to the warm cache, otherwise incomplete totals may
exist for today's date in the cache tomorrow. Only adding the totals to the
warm cache for yesterday or older fixes this.
Kevin Peters 3 jaren geleden
bovenliggende
commit
bc4ce9cb86
1 gewijzigde bestanden met toevoegingen van 7 en 8 verwijderingen
  1. 7 8
      event_database/cloud_functions/totals.go

+ 7 - 8
event_database/cloud_functions/totals.go

@@ -122,14 +122,7 @@ func createCountsOfInterval(tbl *bigtable.Table, ctx context.Context, prefix str
 						intervalsWG.Done()
 						return
 					}
-				} else {
-					// no cache for this query
-					warmTotalsCache[dateStr][cachePrefix] = map[string]int{}
 				}
-			} else {
-				// no cache for this date, initialize the map
-				warmTotalsCache[dateStr] = map[string]map[string]int{}
-				warmTotalsCache[dateStr][cachePrefix] = map[string]int{}
 			}
 			muWarmTotalsCache.Unlock()
 
@@ -155,7 +148,13 @@ func createCountsOfInterval(tbl *bigtable.Table, ctx context.Context, prefix str
 
 			if daysAgo >= 1 {
 				muWarmTotalsCache.Lock()
-				if cacheData, ok := warmTotalsCache[dateStr][cachePrefix]; !ok || len(cacheData) <= 1 || !useCache(dateStr) {
+				if _, ok := warmTotalsCache[dateStr]; !ok {
+					warmTotalsCache[dateStr] = map[string]map[string]int{}
+				}
+				if _, ok := warmTotalsCache[dateStr][cachePrefix]; !ok {
+					warmTotalsCache[dateStr][cachePrefix] = map[string]int{}
+				}
+				if len(warmTotalsCache[dateStr][cachePrefix]) <= 1 || !useCache(dateStr) {
 					// set the result in the cache
 					warmTotalsCache[dateStr][cachePrefix] = results[dateStr]
 					cacheNeedsUpdate = true