fix count() cache retrieval

This commit is contained in:
Ben Johnson 2016-08-12 10:02:57 -06:00
parent 07a815eb55
commit 76af8b53a3
No known key found for this signature in database
GPG key ID: 81741CD251883081
2 changed files with 12 additions and 1 deletions

View file

@ -51,7 +51,8 @@ func (c *LRUCache) Add(bitmapID, n uint64) {
// Get returns a bitmap with a given id.
func (c *LRUCache) Get(bitmapID uint64) uint64 {
n, _ := c.cache.Get(bitmapID)
return n.(uint64)
nn, _ := n.(uint64)
return nn
}
// Len returns the number of items in the cache.

View file

@ -527,6 +527,16 @@ func (f *Fragment) topBitmapPairs(bitmapIDs []uint64) []BitmapPair {
// Otherwise retrieve specific bitmaps.
pairs := make([]BitmapPair, len(bitmapIDs))
for i, bitmapID := range bitmapIDs {
// Look up cache first, if available.
if n := f.cache.Get(bitmapID); n > 0 {
pairs[i] = BitmapPair{
ID: bitmapID,
Count: n,
}
continue
}
// Otherwise load from storage.
pairs[i] = BitmapPair{
ID: bitmapID,
Count: f.Bitmap(bitmapID).Count(),