From 8ab095f675af8c9af7509abc1efbfe45429d69ec Mon Sep 17 00:00:00 2001 From: alexandra-3 <118532397+alexandra-3@users.noreply.github.com> Date: Thu, 16 Feb 2023 09:20:14 +1000 Subject: [PATCH] Sort duplicate scenes by path (#3157) --- pkg/sqlite/scene.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/sqlite/scene.go b/pkg/sqlite/scene.go index e6aef4404..e7657677d 100644 --- a/pkg/sqlite/scene.go +++ b/pkg/sqlite/scene.go @@ -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 +}