Skip to content

Commit

Permalink
Skip boltdb update call when queue is empty
Browse files Browse the repository at this point in the history
This prevents unnecessary calls (and disk writes) to the metadata cache db when there are
no items in the queue.

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
  • Loading branch information
alexcb committed Nov 8, 2022
1 parent 5b7315c commit 0bb8505
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cache/metadata/metadata.go
Expand Up @@ -317,6 +317,9 @@ func (s *StorageItem) Queue(fn func(b *bolt.Bucket) error) {
func (s *StorageItem) Commit() error {
s.qmu.Lock()
defer s.qmu.Unlock()
if len(s.queue) == 0 {
return nil
}
return errors.WithStack(s.Update(func(b *bolt.Bucket) error {
for _, fn := range s.queue {
if err := fn(b); err != nil {
Expand Down

0 comments on commit 0bb8505

Please sign in to comment.