Fix bulk tagger again (#4133)

* Add ForEndpoint method
* Fix typo in schema 48 migration
This commit is contained in:
DingDongSoLong4
2023-09-20 03:15:48 +02:00
committed by GitHub
parent 7ba7df052d
commit 36e9ed7a6c
3 changed files with 18 additions and 5 deletions

View File

@@ -383,8 +383,8 @@ func (s *Manager) StashBoxBatchPerformerTag(ctx context.Context, input StashBoxB
} }
// Check if the user wants to refresh existing or new items // Check if the user wants to refresh existing or new items
if (input.Refresh && len(performer.StashIDs.List()) > 0) || hasStashID := performer.StashIDs.ForEndpoint(box.Endpoint) != nil
(!input.Refresh && len(performer.StashIDs.List()) == 0) { if (input.Refresh && hasStashID) || (!input.Refresh && !hasStashID) {
tasks = append(tasks, StashBoxBatchTagTask{ tasks = append(tasks, StashBoxBatchTagTask{
performer: performer, performer: performer,
refresh: input.Refresh, 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 // Check if the user wants to refresh existing or new items
if (input.Refresh && len(studio.StashIDs.List()) > 0) || hasStashID := studio.StashIDs.ForEndpoint(box.Endpoint) != nil
(!input.Refresh && len(studio.StashIDs.List()) == 0) { if (input.Refresh && hasStashID) || (!input.Refresh && !hasStashID) {
tasks = append(tasks, StashBoxBatchTagTask{ tasks = append(tasks, StashBoxBatchTagTask{
studio: studio, studio: studio,
refresh: input.Refresh, refresh: input.Refresh,

View File

@@ -208,6 +208,19 @@ func (r RelatedStashIDs) List() []StashID {
return r.list 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 { func (r *RelatedStashIDs) load(fn func() ([]StashID, error)) error {
if r.Loaded() { if r.Loaded() {
return nil return nil

View File

@@ -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) _, err := m.db.Exec("UPDATE studios SET name = ? WHERE id = ?", newName, id)
if err != nil { if err != nil {
return err return err