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.
This commit is contained in:
Kevin Peters 2022-05-03 15:26:12 +00:00 committed by Evan Gray
parent 4d54fee0b9
commit bc4ce9cb86
1 changed files with 7 additions and 8 deletions

View File

@ -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