From 36e9ed7a6cb08bfa15339038280b764bcbfde242 Mon Sep 17 00:00:00 2001 From: DingDongSoLong4 <99329275+DingDongSoLong4@users.noreply.github.com> Date: Wed, 20 Sep 2023 03:15:48 +0200 Subject: [PATCH] Fix bulk tagger again (#4133) * Add ForEndpoint method * Fix typo in schema 48 migration --- internal/manager/manager_tasks.go | 8 ++++---- pkg/models/relationships.go | 13 +++++++++++++ pkg/sqlite/migrations/48_premigrate.go | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/internal/manager/manager_tasks.go b/internal/manager/manager_tasks.go index e69dccf1dfa..ed4eea17116 100644 --- a/internal/manager/manager_tasks.go +++ b/internal/manager/manager_tasks.go @@ -383,8 +383,8 @@ func (s *Manager) StashBoxBatchPerformerTag(ctx context.Context, input StashBoxB } // Check if the user wants to refresh existing or new items - if (input.Refresh && len(performer.StashIDs.List()) > 0) || - (!input.Refresh && len(performer.StashIDs.List()) == 0) { + hasStashID := performer.StashIDs.ForEndpoint(box.Endpoint) != nil + if (input.Refresh && hasStashID) || (!input.Refresh && !hasStashID) { tasks = append(tasks, StashBoxBatchTagTask{ performer: performer, refresh: input.Refresh, @@ -516,8 +516,8 @@ func (s *Manager) StashBoxBatchStudioTag(ctx context.Context, input StashBoxBatc } // Check if the user wants to refresh existing or new items - if (input.Refresh && len(studio.StashIDs.List()) > 0) || - (!input.Refresh && len(studio.StashIDs.List()) == 0) { + hasStashID := studio.StashIDs.ForEndpoint(box.Endpoint) != nil + if (input.Refresh && hasStashID) || (!input.Refresh && !hasStashID) { tasks = append(tasks, StashBoxBatchTagTask{ studio: studio, refresh: input.Refresh, diff --git a/pkg/models/relationships.go b/pkg/models/relationships.go index 2e6f07708a0..2c2bc60b10b 100644 --- a/pkg/models/relationships.go +++ b/pkg/models/relationships.go @@ -208,6 +208,19 @@ func (r RelatedStashIDs) List() []StashID { return r.list } +// ForID returns the StashID object for the given endpoint. Returns nil if not found. +func (r *RelatedStashIDs) ForEndpoint(endpoint string) *StashID { + r.mustLoaded() + + for _, v := range r.list { + if v.Endpoint == endpoint { + return &v + } + } + + return nil +} + func (r *RelatedStashIDs) load(fn func() ([]StashID, error)) error { if r.Loaded() { return nil diff --git a/pkg/sqlite/migrations/48_premigrate.go b/pkg/sqlite/migrations/48_premigrate.go index b16c2258f9d..f0e59620e04 100644 --- a/pkg/sqlite/migrations/48_premigrate.go +++ b/pkg/sqlite/migrations/48_premigrate.go @@ -130,7 +130,7 @@ func (m *schema48PreMigrator) fixStudioNames(ctx context.Context) error { } } - logger.Info("Renaming duplicate studio id %d to %s", id, newName) + logger.Infof("Renaming duplicate studio id %d to %s", id, newName) _, err := m.db.Exec("UPDATE studios SET name = ? WHERE id = ?", newName, id) if err != nil { return err