From 37cc68a9f70d30618f80a32566fe5112c272359d Mon Sep 17 00:00:00 2001 From: comp500 Date: Fri, 24 Mar 2023 01:00:05 +0000 Subject: [PATCH] Significantly improve refreshing performance Looping through every file on every file update *and* cleaning + fromslash is sloww with many files (ideally, we'd have a map to look up the file, but this is already significantly faster) --- core/index.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/index.go b/core/index.go index c26e781..59ab917 100644 --- a/core/index.go +++ b/core/index.go @@ -84,8 +84,10 @@ func (in *Index) updateFileHashGiven(path, format, hash string, mod bool) error if err != nil { return err } + slashPath := filepath.ToSlash(relPath) + // TODO: make this not a linear scan for every file update for k, v := range in.Files { - if filepath.Clean(filepath.FromSlash(v.File)) == relPath { + if v.File == slashPath { found = true // Update hash in.Files[k].Hash = hash @@ -96,15 +98,14 @@ func (in *Index) updateFileHashGiven(path, format, hash string, mod bool) error } // Mark this file as found in.Files[k].fileExistsTemp = true - // Clean up path if it's untidy - in.Files[k].File = filepath.ToSlash(relPath) + in.Files[k].File = slashPath // Don't break out of loop, as there may be aliased versions that // also need to be updated } } if !found { newFile := IndexFile{ - File: filepath.ToSlash(relPath), + File: slashPath, Hash: hash, fileExistsTemp: true, }