sync: idx values from reposAlphabeticalOrder do not match reposCache indexes
This commit is contained in:
parent
8321129ac8
commit
b84b7bdb4e
1
main.go
1
main.go
@ -36,6 +36,7 @@ type Application struct {
|
|||||||
|
|
||||||
reposMut sync.RWMutex
|
reposMut sync.RWMutex
|
||||||
reposCache []gitea.Repo // Sorted by recently-created-first
|
reposCache []gitea.Repo // Sorted by recently-created-first
|
||||||
|
reposCacheByName map[string]int
|
||||||
reposAlphabeticalOrder map[string]int
|
reposAlphabeticalOrder map[string]int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
sync.go
8
sync.go
@ -94,7 +94,7 @@ func (this *Application) sync(ctx context.Context) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, rr := range repos {
|
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
|
// Already exists in cache with same Gitea update time
|
||||||
// Copy timestamps
|
// Copy timestamps
|
||||||
repos[i] = this.reposCache[idx]
|
repos[i] = this.reposCache[idx]
|
||||||
@ -156,9 +156,15 @@ func (this *Application) sync(ctx context.Context) (bool, error) {
|
|||||||
repos = reordered
|
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
|
// Commit our changes for the other threads to look at
|
||||||
this.reposMut.Lock()
|
this.reposMut.Lock()
|
||||||
this.reposCache = repos
|
this.reposCache = repos
|
||||||
|
this.reposCacheByName = reposCacheByName
|
||||||
this.reposAlphabeticalOrder = alphabeticalOrderIndexes
|
this.reposAlphabeticalOrder = alphabeticalOrderIndexes
|
||||||
this.reposMut.Unlock()
|
this.reposMut.Unlock()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user