Sort duplicate scenes by path (#3157)

This commit is contained in:
alexandra-3 2023-02-16 09:20:14 +10:00 committed by GitHub
parent ebf3a4ba8e
commit 8ab095f675
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"path/filepath"
"sort"
"strconv"
"strings"
"time"
@ -1706,5 +1707,26 @@ func (qb *SceneStore) FindDuplicates(ctx context.Context, distance int) ([][]*mo
}
}
sortByPath(duplicates)
return duplicates, nil
}
func sortByPath(scenes [][]*models.Scene) {
lessFunc := func(i int, j int) bool {
firstPathI := getFirstPath(scenes[i])
firstPathJ := getFirstPath(scenes[j])
return firstPathI < firstPathJ
}
sort.SliceStable(scenes, lessFunc)
}
func getFirstPath(scenes []*models.Scene) string {
var firstPath string
for i, scene := range scenes {
if i == 0 || scene.Path < firstPath {
firstPath = scene.Path
}
}
return firstPath
}