sync: idx values from reposAlphabeticalOrder do not match reposCache indexes

This commit is contained in:
mappu 2022-12-31 14:55:00 +13:00
parent 8321129ac8
commit b84b7bdb4e
2 changed files with 8 additions and 1 deletions

View File

@ -36,6 +36,7 @@ type Application struct {
reposMut sync.RWMutex
reposCache []gitea.Repo // Sorted by recently-created-first
reposCacheByName map[string]int
reposAlphabeticalOrder map[string]int
}

View File

@ -94,7 +94,7 @@ func (this *Application) sync(ctx context.Context) (bool, error) {
}
for i, rr := range repos {
if idx, ok := this.reposAlphabeticalOrder[rr.Name]; ok && this.reposCache[idx].GiteaUpdated == rr.GiteaUpdated {
if idx, ok := this.reposCacheByName[rr.Name]; ok && this.reposCache[idx].GiteaUpdated == rr.GiteaUpdated {
// Already exists in cache with same Gitea update time
// Copy timestamps
repos[i] = this.reposCache[idx]
@ -156,9 +156,15 @@ func (this *Application) sync(ctx context.Context) (bool, error) {
repos = reordered
}
reposCacheByName := make(map[string]int, len(repos))
for idx, repo := range repos {
reposCacheByName[repo.Name] = idx
}
// Commit our changes for the other threads to look at
this.reposMut.Lock()
this.reposCache = repos
this.reposCacheByName = reposCacheByName
this.reposAlphabeticalOrder = alphabeticalOrderIndexes
this.reposMut.Unlock()