From 4daca97f8939daa7615d1a658acd0d6168c3788d Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Mon, 19 Apr 2021 18:37:47 +0000 Subject: [PATCH] Only rewrite metadata file when the download counter changed Previously, the metadata file would be rewritten even if the download counter stayed the same (i.e. `increaseDownload = false`, previews and HEAD requests). Because the metadata doesn't change in that case, this would simply rewrite the exact same contents needlessly, which may also incur extra costs depending on the storage backend. --- server/handlers.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/server/handlers.go b/server/handlers.go index 7686c46..5bcce03 100644 --- a/server/handlers.go +++ b/server/handlers.go @@ -661,13 +661,11 @@ func (s *Server) CheckMetadata(token, filename string, increaseDownload bool) (M return metadata, errors.New("MaxDownloads expired.") } else if !metadata.MaxDate.IsZero() && time.Now().After(metadata.MaxDate) { return metadata, errors.New("MaxDate expired.") - } else { + } else if increaseDownload { // todo(nl5887): mutex? // update number of downloads - if increaseDownload { - metadata.Downloads++ - } + metadata.Downloads++ buffer := &bytes.Buffer{} if err := json.NewEncoder(buffer).Encode(metadata); err != nil {