mirror of
https://github.com/stashapp/stash.git
synced 2025-12-08 01:13:09 +01:00
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:
parent
1e05766571
commit
b8af147a8d
5 changed files with 82 additions and 46 deletions
|
|
@ -123,10 +123,12 @@ func Test_PerformerStore_Create(t *testing.T) {
|
||||||
{
|
{
|
||||||
StashID: stashID1,
|
StashID: stashID1,
|
||||||
Endpoint: endpoint1,
|
Endpoint: endpoint1,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
StashID: stashID2,
|
StashID: stashID2,
|
||||||
Endpoint: endpoint2,
|
Endpoint: endpoint2,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
CreatedAt: createdAt,
|
CreatedAt: createdAt,
|
||||||
|
|
@ -285,10 +287,12 @@ func Test_PerformerStore_Update(t *testing.T) {
|
||||||
{
|
{
|
||||||
StashID: stashID1,
|
StashID: stashID1,
|
||||||
Endpoint: endpoint1,
|
Endpoint: endpoint1,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
StashID: stashID2,
|
StashID: stashID2,
|
||||||
Endpoint: endpoint2,
|
Endpoint: endpoint2,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
CreatedAt: createdAt,
|
CreatedAt: createdAt,
|
||||||
|
|
@ -520,10 +524,12 @@ func Test_PerformerStore_UpdatePartial(t *testing.T) {
|
||||||
{
|
{
|
||||||
StashID: stashID1,
|
StashID: stashID1,
|
||||||
Endpoint: endpoint1,
|
Endpoint: endpoint1,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
StashID: stashID2,
|
StashID: stashID2,
|
||||||
Endpoint: endpoint2,
|
Endpoint: endpoint2,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Mode: models.RelationshipUpdateModeSet,
|
Mode: models.RelationshipUpdateModeSet,
|
||||||
|
|
@ -562,10 +568,12 @@ func Test_PerformerStore_UpdatePartial(t *testing.T) {
|
||||||
{
|
{
|
||||||
StashID: stashID1,
|
StashID: stashID1,
|
||||||
Endpoint: endpoint1,
|
Endpoint: endpoint1,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
StashID: stashID2,
|
StashID: stashID2,
|
||||||
Endpoint: endpoint2,
|
Endpoint: endpoint2,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
CreatedAt: createdAt,
|
CreatedAt: createdAt,
|
||||||
|
|
@ -2077,6 +2085,7 @@ func testPerformerStashIDs(ctx context.Context, t *testing.T, s *models.Performe
|
||||||
stashID := models.StashID{
|
stashID := models.StashID{
|
||||||
StashID: stashIDStr,
|
StashID: stashIDStr,
|
||||||
Endpoint: endpoint,
|
Endpoint: endpoint,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
qb := db.Performer
|
qb := db.Performer
|
||||||
|
|
|
||||||
|
|
@ -135,10 +135,12 @@ func Test_sceneQueryBuilder_Create(t *testing.T) {
|
||||||
{
|
{
|
||||||
StashID: stashID1,
|
StashID: stashID1,
|
||||||
Endpoint: endpoint1,
|
Endpoint: endpoint1,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
StashID: stashID2,
|
StashID: stashID2,
|
||||||
Endpoint: endpoint2,
|
Endpoint: endpoint2,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
ResumeTime: float64(resumeTime),
|
ResumeTime: float64(resumeTime),
|
||||||
|
|
@ -180,10 +182,12 @@ func Test_sceneQueryBuilder_Create(t *testing.T) {
|
||||||
{
|
{
|
||||||
StashID: stashID1,
|
StashID: stashID1,
|
||||||
Endpoint: endpoint1,
|
Endpoint: endpoint1,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
StashID: stashID2,
|
StashID: stashID2,
|
||||||
Endpoint: endpoint2,
|
Endpoint: endpoint2,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
ResumeTime: resumeTime,
|
ResumeTime: resumeTime,
|
||||||
|
|
@ -364,10 +368,12 @@ func Test_sceneQueryBuilder_Update(t *testing.T) {
|
||||||
{
|
{
|
||||||
StashID: stashID1,
|
StashID: stashID1,
|
||||||
Endpoint: endpoint1,
|
Endpoint: endpoint1,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
StashID: stashID2,
|
StashID: stashID2,
|
||||||
Endpoint: endpoint2,
|
Endpoint: endpoint2,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
ResumeTime: resumeTime,
|
ResumeTime: resumeTime,
|
||||||
|
|
@ -592,10 +598,12 @@ func Test_sceneQueryBuilder_UpdatePartial(t *testing.T) {
|
||||||
{
|
{
|
||||||
StashID: stashID1,
|
StashID: stashID1,
|
||||||
Endpoint: endpoint1,
|
Endpoint: endpoint1,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
StashID: stashID2,
|
StashID: stashID2,
|
||||||
Endpoint: endpoint2,
|
Endpoint: endpoint2,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Mode: models.RelationshipUpdateModeSet,
|
Mode: models.RelationshipUpdateModeSet,
|
||||||
|
|
@ -636,10 +644,12 @@ func Test_sceneQueryBuilder_UpdatePartial(t *testing.T) {
|
||||||
{
|
{
|
||||||
StashID: stashID1,
|
StashID: stashID1,
|
||||||
Endpoint: endpoint1,
|
Endpoint: endpoint1,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
StashID: stashID2,
|
StashID: stashID2,
|
||||||
Endpoint: endpoint2,
|
Endpoint: endpoint2,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
ResumeTime: resumeTime,
|
ResumeTime: resumeTime,
|
||||||
|
|
@ -743,10 +753,12 @@ func Test_sceneQueryBuilder_UpdatePartialRelationships(t *testing.T) {
|
||||||
{
|
{
|
||||||
StashID: stashID1,
|
StashID: stashID1,
|
||||||
Endpoint: endpoint1,
|
Endpoint: endpoint1,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
StashID: stashID2,
|
StashID: stashID2,
|
||||||
Endpoint: endpoint2,
|
Endpoint: endpoint2,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -4379,6 +4391,7 @@ func testSceneStashIDs(ctx context.Context, t *testing.T, s *models.Scene) {
|
||||||
stashID := models.StashID{
|
stashID := models.StashID{
|
||||||
StashID: stashIDStr,
|
StashID: stashIDStr,
|
||||||
Endpoint: endpoint,
|
Endpoint: endpoint,
|
||||||
|
UpdatedAt: epochTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
qb := db.Scene
|
qb := db.Scene
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ import (
|
||||||
_ "github.com/stashapp/stash/pkg/sqlite/migrations"
|
_ "github.com/stashapp/stash/pkg/sqlite/migrations"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var epochTime = time.Unix(0, 0).UTC()
|
||||||
|
|
||||||
const (
|
const (
|
||||||
spacedSceneTitle = "zzz yyy xxx"
|
spacedSceneTitle = "zzz yyy xxx"
|
||||||
)
|
)
|
||||||
|
|
@ -1030,6 +1032,7 @@ func sceneStashID(i int) models.StashID {
|
||||||
return models.StashID{
|
return models.StashID{
|
||||||
StashID: getSceneStringValue(i, "stashid"),
|
StashID: getSceneStringValue(i, "stashid"),
|
||||||
Endpoint: getSceneStringValue(i, "endpoint"),
|
Endpoint: getSceneStringValue(i, "endpoint"),
|
||||||
|
UpdatedAt: epochTime,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -618,6 +618,9 @@ func testStudioStashIDs(ctx context.Context, t *testing.T, s *models.Studio) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #5563 - set the UpdatedAt field to epoch
|
||||||
|
stashID.UpdatedAt = epochTime
|
||||||
|
|
||||||
assert.Equal(t, []models.StashID{stashID}, s.StashIDs.List())
|
assert.Equal(t, []models.StashID{stashID}, s.StashIDs.List())
|
||||||
|
|
||||||
// remove stash ids and ensure was updated
|
// remove stash ids and ensure was updated
|
||||||
|
|
|
||||||
|
|
@ -309,7 +309,15 @@ func (t *stashIDTable) get(ctx context.Context, id int) ([]models.StashID, error
|
||||||
return ret, nil
|
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) {
|
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(
|
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},
|
goqu.Vals{id, v.Endpoint, v.StashID, v.UpdatedAt},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue