Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 5b1cde5

Browse files
committed
Modify cache to delete more than one item to free space
The previous version could only delete the oldest used object. If the object to cache was bigger than the space freed it could not be added. Also the decoder adds bases to the cache when they are needed. This change increases the speed creating indexes 2x. Signed-off-by: Javi Fontan <jfontan@gmail.com>
1 parent 4d43799 commit 5b1cde5

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

plumbing/cache/object_lru.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,14 @@ func (c *ObjectLRU) Put(obj plumbing.EncodedObject) {
5555
return
5656
}
5757

58-
if c.actualSize+objSize > c.MaxSize {
58+
for c.actualSize+objSize > c.MaxSize {
5959
last := c.ll.Back()
6060
lastObj := last.Value.(plumbing.EncodedObject)
6161
lastSize := FileSize(lastObj.Size())
6262

6363
c.ll.Remove(last)
6464
delete(c.cache, lastObj.Hash())
6565
c.actualSize -= lastSize
66-
67-
if c.actualSize+objSize > c.MaxSize {
68-
return
69-
}
7066
}
7167

7268
ee := c.ll.PushFront(obj)

plumbing/format/packfile/decoder.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ func (d *Decoder) fillOFSDeltaObjectContent(obj plumbing.EncodedObject, offset i
407407
if err != nil {
408408
return 0, err
409409
}
410+
411+
d.cachePut(base)
410412
}
411413

412414
obj.SetType(base.Type())

0 commit comments

Comments
 (0)