Skip to content

Commit

Permalink
Fix bulk tagger again (stashapp#4133)
Browse files Browse the repository at this point in the history
* Add ForEndpoint method
* Fix typo in schema 48 migration
  • Loading branch information
DingDongSoLong4 authored Sep 20, 2023
1 parent 7ba7df0 commit 36e9ed7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
8 changes: 4 additions & 4 deletions internal/manager/manager_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions pkg/models/relationships.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/sqlite/migrations/48_premigrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 36e9ed7

Please sign in to comment.