Initialise UpdatedAt for stash ids (#5680)

* Initialise imported zero time to epoch time

Fixes null time error after importing stash id without updatedAt set

* Update unit tests
This commit is contained in:
WithoutPants 2025-02-26 08:03:35 +11:00 committed by GitHub
parent 1e05766571
commit b8af147a8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 82 additions and 46 deletions

View file

@ -123,10 +123,12 @@ func Test_PerformerStore_Create(t *testing.T) {
{
StashID: stashID1,
Endpoint: endpoint1,
UpdatedAt: epochTime,
},
{
StashID: stashID2,
Endpoint: endpoint2,
UpdatedAt: epochTime,
},
}),
CreatedAt: createdAt,
@ -285,10 +287,12 @@ func Test_PerformerStore_Update(t *testing.T) {
{
StashID: stashID1,
Endpoint: endpoint1,
UpdatedAt: epochTime,
},
{
StashID: stashID2,
Endpoint: endpoint2,
UpdatedAt: epochTime,
},
}),
CreatedAt: createdAt,
@ -520,10 +524,12 @@ func Test_PerformerStore_UpdatePartial(t *testing.T) {
{
StashID: stashID1,
Endpoint: endpoint1,
UpdatedAt: epochTime,
},
{
StashID: stashID2,
Endpoint: endpoint2,
UpdatedAt: epochTime,
},
},
Mode: models.RelationshipUpdateModeSet,
@ -562,10 +568,12 @@ func Test_PerformerStore_UpdatePartial(t *testing.T) {
{
StashID: stashID1,
Endpoint: endpoint1,
UpdatedAt: epochTime,
},
{
StashID: stashID2,
Endpoint: endpoint2,
UpdatedAt: epochTime,
},
}),
CreatedAt: createdAt,
@ -2077,6 +2085,7 @@ func testPerformerStashIDs(ctx context.Context, t *testing.T, s *models.Performe
stashID := models.StashID{
StashID: stashIDStr,
Endpoint: endpoint,
UpdatedAt: epochTime,
}
qb := db.Performer

View file

@ -135,10 +135,12 @@ func Test_sceneQueryBuilder_Create(t *testing.T) {
{
StashID: stashID1,
Endpoint: endpoint1,
UpdatedAt: epochTime,
},
{
StashID: stashID2,
Endpoint: endpoint2,
UpdatedAt: epochTime,
},
}),
ResumeTime: float64(resumeTime),
@ -180,10 +182,12 @@ func Test_sceneQueryBuilder_Create(t *testing.T) {
{
StashID: stashID1,
Endpoint: endpoint1,
UpdatedAt: epochTime,
},
{
StashID: stashID2,
Endpoint: endpoint2,
UpdatedAt: epochTime,
},
}),
ResumeTime: resumeTime,
@ -364,10 +368,12 @@ func Test_sceneQueryBuilder_Update(t *testing.T) {
{
StashID: stashID1,
Endpoint: endpoint1,
UpdatedAt: epochTime,
},
{
StashID: stashID2,
Endpoint: endpoint2,
UpdatedAt: epochTime,
},
}),
ResumeTime: resumeTime,
@ -592,10 +598,12 @@ func Test_sceneQueryBuilder_UpdatePartial(t *testing.T) {
{
StashID: stashID1,
Endpoint: endpoint1,
UpdatedAt: epochTime,
},
{
StashID: stashID2,
Endpoint: endpoint2,
UpdatedAt: epochTime,
},
},
Mode: models.RelationshipUpdateModeSet,
@ -636,10 +644,12 @@ func Test_sceneQueryBuilder_UpdatePartial(t *testing.T) {
{
StashID: stashID1,
Endpoint: endpoint1,
UpdatedAt: epochTime,
},
{
StashID: stashID2,
Endpoint: endpoint2,
UpdatedAt: epochTime,
},
}),
ResumeTime: resumeTime,
@ -743,10 +753,12 @@ func Test_sceneQueryBuilder_UpdatePartialRelationships(t *testing.T) {
{
StashID: stashID1,
Endpoint: endpoint1,
UpdatedAt: epochTime,
},
{
StashID: stashID2,
Endpoint: endpoint2,
UpdatedAt: epochTime,
},
}
)
@ -4379,6 +4391,7 @@ func testSceneStashIDs(ctx context.Context, t *testing.T, s *models.Scene) {
stashID := models.StashID{
StashID: stashIDStr,
Endpoint: endpoint,
UpdatedAt: epochTime,
}
qb := db.Scene

View file

@ -24,6 +24,8 @@ import (
_ "github.com/stashapp/stash/pkg/sqlite/migrations"
)
var epochTime = time.Unix(0, 0).UTC()
const (
spacedSceneTitle = "zzz yyy xxx"
)
@ -1030,6 +1032,7 @@ func sceneStashID(i int) models.StashID {
return models.StashID{
StashID: getSceneStringValue(i, "stashid"),
Endpoint: getSceneStringValue(i, "endpoint"),
UpdatedAt: epochTime,
}
}

View file

@ -618,6 +618,9 @@ func testStudioStashIDs(ctx context.Context, t *testing.T, s *models.Studio) {
return
}
// #5563 - set the UpdatedAt field to epoch
stashID.UpdatedAt = epochTime
assert.Equal(t, []models.StashID{stashID}, s.StashIDs.List())
// remove stash ids and ensure was updated

View file

@ -309,7 +309,15 @@ func (t *stashIDTable) get(ctx context.Context, id int) ([]models.StashID, error
return ret, nil
}
var epochTime = time.Unix(0, 0).UTC()
func (t *stashIDTable) insertJoin(ctx context.Context, id int, v models.StashID) (sql.Result, error) {
// #5563 - it's possible that zero-value updated at timestamps are provided via import
// replace them with the epoch time
if v.UpdatedAt.IsZero() {
v.UpdatedAt = epochTime
}
var q = dialect.Insert(t.table.table).Cols(t.idColumn.GetCol(), "endpoint", "stash_id", "updated_at").Vals(
goqu.Vals{id, v.Endpoint, v.StashID, v.UpdatedAt},
)