Skip to content

Commit

Permalink
Fingerprints fix for postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
NodudeWasTaken committed Oct 28, 2024
1 parent 2c0c951 commit 4e34a50
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/sqlite/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ func (qb *FileStore) getMany(ctx context.Context, q *goqu.SelectDataset) ([]mode
return err
}

f.fingerprintQueryRow.correct()

rows = append(rows, f)
return nil
}); err != nil {
Expand Down
15 changes: 15 additions & 0 deletions pkg/sqlite/fingerprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package sqlite
import (
"context"
"fmt"
"strconv"
"strings"

"github.com/doug-martin/goqu/v9"
"github.com/doug-martin/goqu/v9/exp"
Expand All @@ -23,6 +25,19 @@ func (r fingerprintQueryRow) valid() bool {
return r.Type.Valid
}

func (r *fingerprintQueryRow) correct() {
if !r.Type.Valid || strings.ToLower(r.Type.String) != "phash" {
return
}
switch r.Fingerprint.(type) {
case string:
i, err := strconv.ParseInt(r.Fingerprint.(string), 10, 64)
if err == nil {
r.Fingerprint = i
}
}
}

func (r *fingerprintQueryRow) resolve() models.Fingerprint {
return models.Fingerprint{
Type: r.Type.String,
Expand Down
15 changes: 15 additions & 0 deletions pkg/sqlite/scene_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ func loadSceneRelationships(ctx context.Context, expected models.Scene, actual *
return nil
}

func sortScene(copy *models.Scene) {
// Ordering is not ensured
copy.GalleryIDs.Sort()
copy.TagIDs.Sort()
copy.PerformerIDs.Sort()
}

func Test_sceneQueryBuilder_Create(t *testing.T) {
var (
title = "title"
Expand Down Expand Up @@ -267,6 +274,8 @@ func Test_sceneQueryBuilder_Create(t *testing.T) {
return
}

sortScene(&copy)
sortScene(&s)
assert.Equal(copy, s)

// ensure can find the scene
Expand All @@ -284,6 +293,7 @@ func Test_sceneQueryBuilder_Create(t *testing.T) {
t.Errorf("loadSceneRelationships() error = %v", err)
return
}
sortScene(found)
assert.Equal(copy, *found)

return
Expand Down Expand Up @@ -492,6 +502,8 @@ func Test_sceneQueryBuilder_Update(t *testing.T) {
return
}

sortScene(&copy)
sortScene(s)
assert.Equal(copy, *s)
})
}
Expand Down Expand Up @@ -699,6 +711,8 @@ func Test_sceneQueryBuilder_UpdatePartial(t *testing.T) {
// ignore file ids
clearSceneFileIDs(got)

sortScene(&tt.want)
sortScene(got)
assert.Equal(tt.want, *got)

s, err := qb.Find(ctx, tt.id)
Expand All @@ -714,6 +728,7 @@ func Test_sceneQueryBuilder_UpdatePartial(t *testing.T) {
// ignore file ids
clearSceneFileIDs(s)

sortScene(s)
assert.Equal(tt.want, *s)
})
}
Expand Down

0 comments on commit 4e34a50

Please sign in to comment.