From f9b6f8fd45c0d5b98a41446ab57c633f1bd436d3 Mon Sep 17 00:00:00 2001 From: greatroar <@> Date: Fri, 17 Jul 2020 10:24:22 +0200 Subject: [PATCH] Replace duplicate type checking in cache with a function --- internal/cache/backend.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/internal/cache/backend.go b/internal/cache/backend.go index 876f30110..93599a73a 100644 --- a/internal/cache/backend.go +++ b/internal/cache/backend.go @@ -43,14 +43,13 @@ func (b *Backend) Remove(ctx context.Context, h restic.Handle) error { return b.Cache.remove(h) } -var autoCacheTypes = map[restic.FileType]struct{}{ - restic.IndexFile: {}, - restic.SnapshotFile: {}, +func autoCached(t restic.FileType) bool { + return t == restic.IndexFile || t == restic.SnapshotFile } // Save stores a new file in the backend and the cache. func (b *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error { - if _, ok := autoCacheTypes[h.Type]; !ok { + if !autoCached(h.Type) { return b.Backend.Save(ctx, h, rd) } @@ -84,11 +83,6 @@ func (b *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindRea return nil } -var autoCacheFiles = map[restic.FileType]bool{ - restic.IndexFile: true, - restic.SnapshotFile: true, -} - func (b *Backend) cacheFile(ctx context.Context, h restic.Handle) error { finish := make(chan struct{}) @@ -192,7 +186,7 @@ func (b *Backend) Load(ctx context.Context, h restic.Handle, length int, offset } // if we don't automatically cache this file type, fall back to the backend - if _, ok := autoCacheFiles[h.Type]; !ok { + if !autoCached(h.Type) { debug.Log("Load(%v, %v, %v): delegating to backend", h, length, offset) return b.Backend.Load(ctx, h, length, offset, consumer) }