don't force immediate recalculate of cache on every update

When writing things that cause additions to the cache, mark it dirty and
flag it for recomputing, but only sometimes actually do the recalculation,
currently implying a 10-second window. We still mark the cache dirty,
so if a request comes in, we'll get fresh data, but the query will be
slowed down because the recomputation will happen then. But that's better
than doing thousands of recalculations which are never used...
This commit is contained in:
Seebs 2021-05-04 14:45:32 -05:00
parent 1e00b50953
commit 130b17b621
2 changed files with 4 additions and 2 deletions

View file

@ -262,6 +262,8 @@ func (c *rankCache) invalidate() {
// The cache will remain flagged as dirty and will be recalculated if Top is called.
// This may cause unexpected memory growth, so record it in metrics for debugging purposes.
c.stats.Count(MetricInvalidateCacheSkipped, 1, 1.0)
// Ensure that we're marked as dirty even if we weren't otherwise.
c.dirty = true
return
}
c.stats.Count(MetricInvalidateCache, 1, 1.0)

View file

@ -2528,7 +2528,7 @@ func (f *fragment) importPositions(tx Tx, set, clear []uint64, rowSet map[uint64
}
if f.CacheType != CacheTypeNone {
f.cache.Recalculate()
f.cache.Invalidate()
}
return nil
}
@ -2826,7 +2826,7 @@ func (f *fragment) unprotectedImportRoaring(ctx context.Context, tx Tx, data []b
}
// we only set this if we need to update the cache
if anyChanged {
f.cache.Recalculate()
f.cache.Invalidate()
}
span, _ = tracing.StartSpanFromContext(ctx, "importRoaring.incrementOpN")