Genericise sliceutil functions (#4253)

* Genericise sliceutil.SliceSame
* Genericise intslice functions
* Genericise stringutil functions
This commit is contained in:
DingDongSoLong4 2023-11-01 23:58:32 +02:00 committed by GitHub
parent cc6673f276
commit 9621213424
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 259 additions and 409 deletions

View file

@ -10,7 +10,7 @@ import (
"github.com/stashapp/stash/pkg/image" "github.com/stashapp/stash/pkg/image"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/plugin" "github.com/stashapp/stash/pkg/plugin"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil/stringslice"
"github.com/stashapp/stash/pkg/utils" "github.com/stashapp/stash/pkg/utils"
) )
@ -256,7 +256,7 @@ func (r *mutationResolver) BulkImageUpdate(ctx context.Context, input BulkImageU
} }
thisUpdatedGalleryIDs := updatedImage.GalleryIDs.ImpactedIDs(i.GalleryIDs.List()) thisUpdatedGalleryIDs := updatedImage.GalleryIDs.ImpactedIDs(i.GalleryIDs.List())
updatedGalleryIDs = intslice.IntAppendUniques(updatedGalleryIDs, thisUpdatedGalleryIDs) updatedGalleryIDs = sliceutil.AppendUniques(updatedGalleryIDs, thisUpdatedGalleryIDs)
} }
image, err := qb.UpdatePartial(ctx, imageID, updatedImage) image, err := qb.UpdatePartial(ctx, imageID, updatedImage)

View file

@ -7,7 +7,7 @@ import (
"github.com/stashapp/stash/internal/manager/config" "github.com/stashapp/stash/internal/manager/config"
"github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/plugin" "github.com/stashapp/stash/pkg/plugin"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
func (r *mutationResolver) RunPluginTask(ctx context.Context, pluginID string, taskName string, args []*plugin.PluginArgInput) (string, error) { func (r *mutationResolver) RunPluginTask(ctx context.Context, pluginID string, taskName string, args []*plugin.PluginArgInput) (string, error) {
@ -41,7 +41,7 @@ func (r *mutationResolver) SetPluginsEnabled(ctx context.Context, enabledMap map
// add plugins that are newly disabled // add plugins that are newly disabled
for pluginID, enabled := range enabledMap { for pluginID, enabled := range enabledMap {
if !enabled { if !enabled {
newDisabled = stringslice.StrAppendUnique(newDisabled, pluginID) newDisabled = sliceutil.AppendUnique(newDisabled, pluginID)
} }
} }

View file

@ -11,7 +11,7 @@ import (
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/plugin" "github.com/stashapp/stash/pkg/plugin"
"github.com/stashapp/stash/pkg/scene" "github.com/stashapp/stash/pkg/scene"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil/stringslice"
"github.com/stashapp/stash/pkg/utils" "github.com/stashapp/stash/pkg/utils"
) )
@ -627,7 +627,7 @@ func (r *mutationResolver) SceneMarkerCreate(ctx context.Context, input SceneMar
// Save the marker tags // Save the marker tags
// If this tag is the primary tag, then let's not add it. // If this tag is the primary tag, then let's not add it.
tagIDs = intslice.IntExclude(tagIDs, []int{newMarker.PrimaryTagID}) tagIDs = sliceutil.Exclude(tagIDs, []int{newMarker.PrimaryTagID})
return qb.UpdateTags(ctx, newMarker.ID, tagIDs) return qb.UpdateTags(ctx, newMarker.ID, tagIDs)
}); err != nil { }); err != nil {
return nil, err return nil, err
@ -716,7 +716,7 @@ func (r *mutationResolver) SceneMarkerUpdate(ctx context.Context, input SceneMar
if tagIdsIncluded { if tagIdsIncluded {
// Save the marker tags // Save the marker tags
// If this tag is the primary tag, then let's not add it. // If this tag is the primary tag, then let's not add it.
tagIDs = intslice.IntExclude(tagIDs, []int{newMarker.PrimaryTagID}) tagIDs = sliceutil.Exclude(tagIDs, []int{newMarker.PrimaryTagID})
if err := qb.UpdateTags(ctx, markerID, tagIDs); err != nil { if err := qb.UpdateTags(ctx, markerID, tagIDs); err != nil {
return err return err
} }

View file

@ -6,7 +6,7 @@ import (
"github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
func (r *queryResolver) FindImage(ctx context.Context, id *string, checksum *string) (*models.Image, error) { func (r *queryResolver) FindImage(ctx context.Context, id *string, checksum *string) (*models.Image, error) {
@ -55,11 +55,11 @@ func (r *queryResolver) FindImages(ctx context.Context, imageFilter *models.Imag
result, err := qb.Query(ctx, models.ImageQueryOptions{ result, err := qb.Query(ctx, models.ImageQueryOptions{
QueryOptions: models.QueryOptions{ QueryOptions: models.QueryOptions{
FindFilter: filter, FindFilter: filter,
Count: stringslice.StrInclude(fields, "count"), Count: sliceutil.Contains(fields, "count"),
}, },
ImageFilter: imageFilter, ImageFilter: imageFilter,
Megapixels: stringslice.StrInclude(fields, "megapixels"), Megapixels: sliceutil.Contains(fields, "megapixels"),
TotalSize: stringslice.StrInclude(fields, "filesize"), TotalSize: sliceutil.Contains(fields, "filesize"),
}) })
if err != nil { if err != nil {
return err return err

View file

@ -8,7 +8,7 @@ import (
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scene" "github.com/stashapp/stash/pkg/scene"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
func (r *queryResolver) FindScene(ctx context.Context, id *string, checksum *string) (*models.Scene, error) { func (r *queryResolver) FindScene(ctx context.Context, id *string, checksum *string) (*models.Scene, error) {
@ -105,11 +105,11 @@ func (r *queryResolver) FindScenes(ctx context.Context, sceneFilter *models.Scen
result, err = r.repository.Scene.Query(ctx, models.SceneQueryOptions{ result, err = r.repository.Scene.Query(ctx, models.SceneQueryOptions{
QueryOptions: models.QueryOptions{ QueryOptions: models.QueryOptions{
FindFilter: filter, FindFilter: filter,
Count: stringslice.StrInclude(fields, "count"), Count: sliceutil.Contains(fields, "count"),
}, },
SceneFilter: sceneFilter, SceneFilter: sceneFilter,
TotalDuration: stringslice.StrInclude(fields, "duration"), TotalDuration: sliceutil.Contains(fields, "duration"),
TotalSize: stringslice.StrInclude(fields, "filesize"), TotalSize: sliceutil.Contains(fields, "filesize"),
}) })
if err == nil { if err == nil {
scenes, err = result.Resolve(ctx) scenes, err = result.Resolve(ctx)
@ -160,11 +160,11 @@ func (r *queryResolver) FindScenesByPathRegex(ctx context.Context, filter *model
result, err := r.repository.Scene.Query(ctx, models.SceneQueryOptions{ result, err := r.repository.Scene.Query(ctx, models.SceneQueryOptions{
QueryOptions: models.QueryOptions{ QueryOptions: models.QueryOptions{
FindFilter: queryFilter, FindFilter: queryFilter,
Count: stringslice.StrInclude(fields, "count"), Count: sliceutil.Contains(fields, "count"),
}, },
SceneFilter: sceneFilter, SceneFilter: sceneFilter,
TotalDuration: stringslice.StrInclude(fields, "duration"), TotalDuration: sliceutil.Contains(fields, "duration"),
TotalSize: stringslice.StrInclude(fields, "filesize"), TotalSize: sliceutil.Contains(fields, "filesize"),
}) })
if err != nil { if err != nil {
return err return err

View file

@ -14,6 +14,7 @@ import (
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scraper" "github.com/stashapp/stash/pkg/scraper"
"github.com/stashapp/stash/pkg/scraper/stashbox" "github.com/stashapp/stash/pkg/scraper/stashbox"
"github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil/stringslice"
) )
@ -80,7 +81,7 @@ func filterSceneTags(scenes []*scraper.ScrapedScene) {
for _, reg := range excludeRegexps { for _, reg := range excludeRegexps {
if reg.MatchString(strings.ToLower(t.Name)) { if reg.MatchString(strings.ToLower(t.Name)) {
ignore = true ignore = true
ignoredTags = stringslice.StrAppendUnique(ignoredTags, t.Name) ignoredTags = sliceutil.AppendUnique(ignoredTags, t.Name)
break break
} }
} }

View file

@ -6,7 +6,7 @@ import (
"github.com/stashapp/stash/pkg/gallery" "github.com/stashapp/stash/pkg/gallery"
"github.com/stashapp/stash/pkg/match" "github.com/stashapp/stash/pkg/match"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
type GalleryFinderUpdater interface { type GalleryFinderUpdater interface {
@ -53,7 +53,7 @@ func GalleryPerformers(ctx context.Context, s *models.Gallery, rw GalleryPerform
} }
existing := s.PerformerIDs.List() existing := s.PerformerIDs.List()
if intslice.IntInclude(existing, otherID) { if sliceutil.Contains(existing, otherID) {
return false, nil return false, nil
} }
@ -91,7 +91,7 @@ func GalleryTags(ctx context.Context, s *models.Gallery, rw GalleryTagUpdater, t
} }
existing := s.TagIDs.List() existing := s.TagIDs.List()
if intslice.IntInclude(existing, otherID) { if sliceutil.Contains(existing, otherID) {
return false, nil return false, nil
} }

View file

@ -6,7 +6,7 @@ import (
"github.com/stashapp/stash/pkg/image" "github.com/stashapp/stash/pkg/image"
"github.com/stashapp/stash/pkg/match" "github.com/stashapp/stash/pkg/match"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
type ImageFinderUpdater interface { type ImageFinderUpdater interface {
@ -44,7 +44,7 @@ func ImagePerformers(ctx context.Context, s *models.Image, rw ImagePerformerUpda
} }
existing := s.PerformerIDs.List() existing := s.PerformerIDs.List()
if intslice.IntInclude(existing, otherID) { if sliceutil.Contains(existing, otherID) {
return false, nil return false, nil
} }
@ -82,7 +82,7 @@ func ImageTags(ctx context.Context, s *models.Image, rw ImageTagUpdater, tagRead
} }
existing := s.TagIDs.List() existing := s.TagIDs.List()
if intslice.IntInclude(existing, otherID) { if sliceutil.Contains(existing, otherID) {
return false, nil return false, nil
} }

View file

@ -8,7 +8,7 @@ import (
"github.com/stashapp/stash/pkg/match" "github.com/stashapp/stash/pkg/match"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scene" "github.com/stashapp/stash/pkg/scene"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/txn" "github.com/stashapp/stash/pkg/txn"
) )
@ -63,7 +63,7 @@ func (tagger *Tagger) PerformerScenes(ctx context.Context, p *models.Performer,
} }
existing := o.PerformerIDs.List() existing := o.PerformerIDs.List()
if intslice.IntInclude(existing, p.ID) { if sliceutil.Contains(existing, p.ID) {
return false, nil return false, nil
} }
@ -92,7 +92,7 @@ func (tagger *Tagger) PerformerImages(ctx context.Context, p *models.Performer,
} }
existing := o.PerformerIDs.List() existing := o.PerformerIDs.List()
if intslice.IntInclude(existing, p.ID) { if sliceutil.Contains(existing, p.ID) {
return false, nil return false, nil
} }
@ -121,7 +121,7 @@ func (tagger *Tagger) PerformerGalleries(ctx context.Context, p *models.Performe
} }
existing := o.PerformerIDs.List() existing := o.PerformerIDs.List()
if intslice.IntInclude(existing, p.ID) { if sliceutil.Contains(existing, p.ID) {
return false, nil return false, nil
} }

View file

@ -6,7 +6,7 @@ import (
"github.com/stashapp/stash/pkg/match" "github.com/stashapp/stash/pkg/match"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scene" "github.com/stashapp/stash/pkg/scene"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
type SceneFinderUpdater interface { type SceneFinderUpdater interface {
@ -44,7 +44,7 @@ func ScenePerformers(ctx context.Context, s *models.Scene, rw ScenePerformerUpda
} }
existing := s.PerformerIDs.List() existing := s.PerformerIDs.List()
if intslice.IntInclude(existing, otherID) { if sliceutil.Contains(existing, otherID) {
return false, nil return false, nil
} }
@ -82,7 +82,7 @@ func SceneTags(ctx context.Context, s *models.Scene, rw SceneTagUpdater, tagRead
} }
existing := s.TagIDs.List() existing := s.TagIDs.List()
if intslice.IntInclude(existing, otherID) { if sliceutil.Contains(existing, otherID) {
return false, nil return false, nil
} }

View file

@ -8,7 +8,7 @@ import (
"github.com/stashapp/stash/pkg/match" "github.com/stashapp/stash/pkg/match"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scene" "github.com/stashapp/stash/pkg/scene"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/txn" "github.com/stashapp/stash/pkg/txn"
) )
@ -61,7 +61,7 @@ func (tagger *Tagger) TagScenes(ctx context.Context, p *models.Tag, paths []stri
} }
existing := o.TagIDs.List() existing := o.TagIDs.List()
if intslice.IntInclude(existing, p.ID) { if sliceutil.Contains(existing, p.ID) {
return false, nil return false, nil
} }
@ -90,7 +90,7 @@ func (tagger *Tagger) TagImages(ctx context.Context, p *models.Tag, paths []stri
} }
existing := o.TagIDs.List() existing := o.TagIDs.List()
if intslice.IntInclude(existing, p.ID) { if sliceutil.Contains(existing, p.ID) {
return false, nil return false, nil
} }
@ -119,7 +119,7 @@ func (tagger *Tagger) TagGalleries(ctx context.Context, p *models.Tag, paths []s
} }
existing := o.TagIDs.List() existing := o.TagIDs.List()
if intslice.IntInclude(existing, p.ID) { if sliceutil.Contains(existing, p.ID) {
return false, nil return false, nil
} }

View file

@ -40,7 +40,7 @@ import (
"github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scene" "github.com/stashapp/stash/pkg/scene"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
var pageSize = 100 var pageSize = 100
@ -522,7 +522,7 @@ func (me *contentDirectoryService) getPageVideos(sceneFilter *models.SceneFilter
} }
func getPageFromID(paths []string) *int { func getPageFromID(paths []string) *int {
i := stringslice.StrIndex(paths, "page") i := sliceutil.Index(paths, "page")
if i == -1 || i+1 >= len(paths) { if i == -1 || i+1 >= len(paths) {
return nil return nil
} }

View file

@ -4,7 +4,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
// only keep the 10 most recent IP addresses // only keep the 10 most recent IP addresses
@ -30,7 +30,7 @@ func (m *ipWhitelistManager) addRecent(addr string) bool {
m.mutex.Lock() m.mutex.Lock()
defer m.mutex.Unlock() defer m.mutex.Unlock()
i := stringslice.StrIndex(m.recentIPAddresses, addr) i := sliceutil.Index(m.recentIPAddresses, addr)
if i != -1 { if i != -1 {
if i == 0 { if i == 0 {
// don't do anything if it's already at the start // don't do anything if it's already at the start

View file

@ -329,7 +329,7 @@ func (t *SceneIdentifier) addTagToScene(ctx context.Context, s *models.Scene, ta
} }
existing := s.TagIDs.List() existing := s.TagIDs.List()
if sliceutil.Include(existing, tagID) { if sliceutil.Contains(existing, tagID) {
// skip if the scene was already tagged // skip if the scene was already tagged
return nil return nil
} }

View file

@ -10,7 +10,7 @@ import (
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/models/mocks" "github.com/stashapp/stash/pkg/models/mocks"
"github.com/stashapp/stash/pkg/scraper" "github.com/stashapp/stash/pkg/scraper"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
) )
@ -23,7 +23,7 @@ type mockSceneScraper struct {
} }
func (s mockSceneScraper) ScrapeScenes(ctx context.Context, sceneID int) ([]*scraper.ScrapedScene, error) { func (s mockSceneScraper) ScrapeScenes(ctx context.Context, sceneID int) ([]*scraper.ScrapedScene, error) {
if intslice.IntInclude(s.errIDs, sceneID) { if sliceutil.Contains(s.errIDs, sceneID) {
return nil, errors.New("scrape scene error") return nil, errors.New("scrape scene error")
} }
return s.results[sceneID], nil return s.results[sceneID], nil

View file

@ -11,7 +11,6 @@ import (
"github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/sliceutil/intslice"
"github.com/stashapp/stash/pkg/utils" "github.com/stashapp/stash/pkg/utils"
) )
@ -111,7 +110,7 @@ func (g sceneRelationships) performers(ctx context.Context, ignoreMale bool) ([]
} }
if performerID != nil { if performerID != nil {
performerIDs = intslice.IntAppendUnique(performerIDs, *performerID) performerIDs = sliceutil.AppendUnique(performerIDs, *performerID)
} }
} }
@ -161,7 +160,7 @@ func (g sceneRelationships) tags(ctx context.Context) ([]int, error) {
return nil, fmt.Errorf("error converting tag ID %s: %w", *t.StoredID, err) return nil, fmt.Errorf("error converting tag ID %s: %w", *t.StoredID, err)
} }
tagIDs = intslice.IntAppendUnique(tagIDs, int(tagID)) tagIDs = sliceutil.AppendUnique(tagIDs, int(tagID))
} else if createMissing { } else if createMissing {
newTag := models.NewTag() newTag := models.NewTag()
newTag.Name = t.Name newTag.Name = t.Name

View file

@ -24,7 +24,7 @@ import (
"github.com/stashapp/stash/pkg/movie" "github.com/stashapp/stash/pkg/movie"
"github.com/stashapp/stash/pkg/performer" "github.com/stashapp/stash/pkg/performer"
"github.com/stashapp/stash/pkg/scene" "github.com/stashapp/stash/pkg/scene"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil/stringslice"
"github.com/stashapp/stash/pkg/studio" "github.com/stashapp/stash/pkg/studio"
"github.com/stashapp/stash/pkg/tag" "github.com/stashapp/stash/pkg/tag"
@ -301,7 +301,7 @@ func (t *ExportTask) populateMovieScenes(ctx context.Context) {
} }
for _, s := range scenes { for _, s := range scenes {
t.scenes.IDs = intslice.IntAppendUnique(t.scenes.IDs, s.ID) t.scenes.IDs = sliceutil.AppendUnique(t.scenes.IDs, s.ID)
} }
} }
} }
@ -337,7 +337,7 @@ func (t *ExportTask) populateGalleryImages(ctx context.Context) {
} }
for _, i := range images { for _, i := range images {
t.images.IDs = intslice.IntAppendUnique(t.images.IDs, i.ID) t.images.IDs = sliceutil.AppendUnique(t.images.IDs, i.ID)
} }
} }
} }
@ -558,26 +558,26 @@ func (t *ExportTask) exportScene(ctx context.Context, wg *sync.WaitGroup, jobCha
if t.includeDependencies { if t.includeDependencies {
if s.StudioID != nil { if s.StudioID != nil {
t.studios.IDs = intslice.IntAppendUnique(t.studios.IDs, *s.StudioID) t.studios.IDs = sliceutil.AppendUnique(t.studios.IDs, *s.StudioID)
} }
t.galleries.IDs = intslice.IntAppendUniques(t.galleries.IDs, gallery.GetIDs(galleries)) t.galleries.IDs = sliceutil.AppendUniques(t.galleries.IDs, gallery.GetIDs(galleries))
tagIDs, err := scene.GetDependentTagIDs(ctx, tagReader, sceneMarkerReader, s) tagIDs, err := scene.GetDependentTagIDs(ctx, tagReader, sceneMarkerReader, s)
if err != nil { if err != nil {
logger.Errorf("[scenes] <%s> error getting scene tags: %s", sceneHash, err.Error()) logger.Errorf("[scenes] <%s> error getting scene tags: %s", sceneHash, err.Error())
continue continue
} }
t.tags.IDs = intslice.IntAppendUniques(t.tags.IDs, tagIDs) t.tags.IDs = sliceutil.AppendUniques(t.tags.IDs, tagIDs)
movieIDs, err := scene.GetDependentMovieIDs(ctx, s) movieIDs, err := scene.GetDependentMovieIDs(ctx, s)
if err != nil { if err != nil {
logger.Errorf("[scenes] <%s> error getting scene movies: %s", sceneHash, err.Error()) logger.Errorf("[scenes] <%s> error getting scene movies: %s", sceneHash, err.Error())
continue continue
} }
t.movies.IDs = intslice.IntAppendUniques(t.movies.IDs, movieIDs) t.movies.IDs = sliceutil.AppendUniques(t.movies.IDs, movieIDs)
t.performers.IDs = intslice.IntAppendUniques(t.performers.IDs, performer.GetIDs(performers)) t.performers.IDs = sliceutil.AppendUniques(t.performers.IDs, performer.GetIDs(performers))
} }
basename := filepath.Base(s.Path) basename := filepath.Base(s.Path)
@ -704,12 +704,12 @@ func (t *ExportTask) exportImage(ctx context.Context, wg *sync.WaitGroup, jobCha
if t.includeDependencies { if t.includeDependencies {
if s.StudioID != nil { if s.StudioID != nil {
t.studios.IDs = intslice.IntAppendUnique(t.studios.IDs, *s.StudioID) t.studios.IDs = sliceutil.AppendUnique(t.studios.IDs, *s.StudioID)
} }
t.galleries.IDs = intslice.IntAppendUniques(t.galleries.IDs, gallery.GetIDs(imageGalleries)) t.galleries.IDs = sliceutil.AppendUniques(t.galleries.IDs, gallery.GetIDs(imageGalleries))
t.tags.IDs = intslice.IntAppendUniques(t.tags.IDs, tag.GetIDs(tags)) t.tags.IDs = sliceutil.AppendUniques(t.tags.IDs, tag.GetIDs(tags))
t.performers.IDs = intslice.IntAppendUniques(t.performers.IDs, performer.GetIDs(performers)) t.performers.IDs = sliceutil.AppendUniques(t.performers.IDs, performer.GetIDs(performers))
} }
fn := newImageJSON.Filename(filepath.Base(s.Path), s.Checksum) fn := newImageJSON.Filename(filepath.Base(s.Path), s.Checksum)
@ -838,11 +838,11 @@ func (t *ExportTask) exportGallery(ctx context.Context, wg *sync.WaitGroup, jobC
if t.includeDependencies { if t.includeDependencies {
if g.StudioID != nil { if g.StudioID != nil {
t.studios.IDs = intslice.IntAppendUnique(t.studios.IDs, *g.StudioID) t.studios.IDs = sliceutil.AppendUnique(t.studios.IDs, *g.StudioID)
} }
t.tags.IDs = intslice.IntAppendUniques(t.tags.IDs, tag.GetIDs(tags)) t.tags.IDs = sliceutil.AppendUniques(t.tags.IDs, tag.GetIDs(tags))
t.performers.IDs = intslice.IntAppendUniques(t.performers.IDs, performer.GetIDs(performers)) t.performers.IDs = sliceutil.AppendUniques(t.performers.IDs, performer.GetIDs(performers))
} }
basename := "" basename := ""
@ -926,7 +926,7 @@ func (t *ExportTask) exportPerformer(ctx context.Context, wg *sync.WaitGroup, jo
newPerformerJSON.Tags = tag.GetNames(tags) newPerformerJSON.Tags = tag.GetNames(tags)
if t.includeDependencies { if t.includeDependencies {
t.tags.IDs = intslice.IntAppendUniques(t.tags.IDs, tag.GetIDs(tags)) t.tags.IDs = sliceutil.AppendUniques(t.tags.IDs, tag.GetIDs(tags))
} }
fn := newPerformerJSON.Filename() fn := newPerformerJSON.Filename()
@ -1116,7 +1116,7 @@ func (t *ExportTask) exportMovie(ctx context.Context, wg *sync.WaitGroup, jobCha
if t.includeDependencies { if t.includeDependencies {
if m.StudioID != nil { if m.StudioID != nil {
t.studios.IDs = intslice.IntAppendUnique(t.studios.IDs, *m.StudioID) t.studios.IDs = sliceutil.AppendUnique(t.studios.IDs, *m.StudioID)
} }
} }

View file

@ -7,7 +7,7 @@ import (
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/models/jsonschema" "github.com/stashapp/stash/pkg/models/jsonschema"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
type ImporterReaderWriter interface { type ImporterReaderWriter interface {
@ -146,8 +146,8 @@ func (i *Importer) populatePerformers(ctx context.Context) error {
pluckedNames = append(pluckedNames, performer.Name) pluckedNames = append(pluckedNames, performer.Name)
} }
missingPerformers := stringslice.StrFilter(names, func(name string) bool { missingPerformers := sliceutil.Filter(names, func(name string) bool {
return !stringslice.StrInclude(pluckedNames, name) return !sliceutil.Contains(pluckedNames, name)
}) })
if len(missingPerformers) > 0 { if len(missingPerformers) > 0 {
@ -205,8 +205,8 @@ func (i *Importer) populateTags(ctx context.Context) error {
pluckedNames = append(pluckedNames, tag.Name) pluckedNames = append(pluckedNames, tag.Name)
} }
missingTags := stringslice.StrFilter(names, func(name string) bool { missingTags := sliceutil.Filter(names, func(name string) bool {
return !stringslice.StrInclude(pluckedNames, name) return !sliceutil.Contains(pluckedNames, name)
}) })
if len(missingTags) > 0 { if len(missingTags) > 0 {

View file

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
type ContentsChangedError struct { type ContentsChangedError struct {
@ -42,7 +42,7 @@ func (s *Service) ValidateImageGalleryChange(ctx context.Context, i *models.Imag
changedIDs = updateIDs.IDs changedIDs = updateIDs.IDs
case models.RelationshipUpdateModeSet: case models.RelationshipUpdateModeSet:
// get the difference between the two lists // get the difference between the two lists
changedIDs = intslice.IntNotIntersect(i.GalleryIDs.List(), updateIDs.IDs) changedIDs = sliceutil.NotIntersect(i.GalleryIDs.List(), updateIDs.IDs)
} }
galleries, err := s.Repository.FindMany(ctx, changedIDs) galleries, err := s.Repository.FindMany(ctx, changedIDs)

View file

@ -7,7 +7,7 @@ import (
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/models/jsonschema" "github.com/stashapp/stash/pkg/models/jsonschema"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
type GalleryFinder interface { type GalleryFinder interface {
@ -229,8 +229,8 @@ func (i *Importer) populatePerformers(ctx context.Context) error {
pluckedNames = append(pluckedNames, performer.Name) pluckedNames = append(pluckedNames, performer.Name)
} }
missingPerformers := stringslice.StrFilter(names, func(name string) bool { missingPerformers := sliceutil.Filter(names, func(name string) bool {
return !stringslice.StrInclude(pluckedNames, name) return !sliceutil.Contains(pluckedNames, name)
}) })
if len(missingPerformers) > 0 { if len(missingPerformers) > 0 {
@ -365,8 +365,8 @@ func importTags(ctx context.Context, tagWriter models.TagFinderCreator, names []
pluckedNames = append(pluckedNames, tag.Name) pluckedNames = append(pluckedNames, tag.Name)
} }
missingTags := stringslice.StrFilter(names, func(name string) bool { missingTags := sliceutil.Filter(names, func(name string) bool {
return !stringslice.StrInclude(pluckedNames, name) return !sliceutil.Contains(pluckedNames, name)
}) })
if len(missingTags) > 0 { if len(missingTags) > 0 {

View file

@ -11,7 +11,7 @@ import (
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/models/paths" "github.com/stashapp/stash/pkg/models/paths"
"github.com/stashapp/stash/pkg/plugin" "github.com/stashapp/stash/pkg/plugin"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/txn" "github.com/stashapp/stash/pkg/txn"
) )
@ -355,7 +355,7 @@ func (h *ScanHandler) getGalleryToAssociate(ctx context.Context, newImage *model
return nil, err return nil, err
} }
if g != nil && !intslice.IntInclude(newImage.GalleryIDs.List(), g.ID) { if g != nil && !sliceutil.Contains(newImage.GalleryIDs.List(), g.ID) {
return g, nil return g, nil
} }

View file

@ -13,7 +13,7 @@ import (
"github.com/stashapp/stash/pkg/image" "github.com/stashapp/stash/pkg/image"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/scene" "github.com/stashapp/stash/pkg/scene"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
const ( const (
@ -67,7 +67,7 @@ func getPathWords(path string, trimExt bool) []string {
// just use the first two characters // just use the first two characters
// #2293 - need to convert to unicode runes for the substring, otherwise // #2293 - need to convert to unicode runes for the substring, otherwise
// the resulting string is corrupted. // the resulting string is corrupted.
ret = stringslice.StrAppendUnique(ret, string([]rune(w)[0:2])) ret = sliceutil.AppendUnique(ret, string([]rune(w)[0:2]))
} }
} }

View file

@ -78,12 +78,12 @@ func (u *UpdateIDs) ImpactedIDs(existing []int) []int {
switch u.Mode { switch u.Mode {
case RelationshipUpdateModeAdd: case RelationshipUpdateModeAdd:
return intslice.IntExclude(u.IDs, existing) return sliceutil.Exclude(u.IDs, existing)
case RelationshipUpdateModeRemove: case RelationshipUpdateModeRemove:
return intslice.IntIntercect(existing, u.IDs) return sliceutil.Intersect(existing, u.IDs)
case RelationshipUpdateModeSet: case RelationshipUpdateModeSet:
// get the difference between the two lists // get the difference between the two lists
return intslice.IntNotIntersect(existing, u.IDs) return sliceutil.NotIntersect(existing, u.IDs)
} }
return nil return nil

View file

@ -9,7 +9,7 @@ import (
"github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/models/jsonschema" "github.com/stashapp/stash/pkg/models/jsonschema"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/utils" "github.com/stashapp/stash/pkg/utils"
) )
@ -74,8 +74,8 @@ func importTags(ctx context.Context, tagWriter models.TagFinderCreator, names []
pluckedNames = append(pluckedNames, tag.Name) pluckedNames = append(pluckedNames, tag.Name)
} }
missingTags := stringslice.StrFilter(names, func(name string) bool { missingTags := sliceutil.Filter(names, func(name string) bool {
return !stringslice.StrInclude(pluckedNames, name) return !sliceutil.Contains(pluckedNames, name)
}) })
if len(missingTags) > 0 { if len(missingTags) > 0 {

View file

@ -19,7 +19,7 @@ import (
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/plugin/common" "github.com/stashapp/stash/pkg/plugin/common"
"github.com/stashapp/stash/pkg/session" "github.com/stashapp/stash/pkg/session"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/txn" "github.com/stashapp/stash/pkg/txn"
) )
@ -140,7 +140,7 @@ func (c Cache) enabledPlugins() []Config {
var ret []Config var ret []Config
for _, p := range c.plugins { for _, p := range c.plugins {
disabled := stringslice.StrInclude(disabledPlugins, p.id) disabled := sliceutil.Contains(disabledPlugins, p.id)
if !disabled { if !disabled {
ret = append(ret, p) ret = append(ret, p)
@ -153,7 +153,7 @@ func (c Cache) enabledPlugins() []Config {
func (c Cache) pluginDisabled(id string) bool { func (c Cache) pluginDisabled(id string) bool {
disabledPlugins := c.config.GetDisabledPlugins() disabledPlugins := c.config.GetDisabledPlugins()
return stringslice.StrInclude(disabledPlugins, id) return sliceutil.Contains(disabledPlugins, id)
} }
// ListPlugins returns plugin details for all of the loaded plugins. // ListPlugins returns plugin details for all of the loaded plugins.
@ -164,7 +164,7 @@ func (c Cache) ListPlugins() []*Plugin {
for _, s := range c.plugins { for _, s := range c.plugins {
p := s.toPlugin() p := s.toPlugin()
disabled := stringslice.StrInclude(disabledPlugins, p.ID) disabled := sliceutil.Contains(disabledPlugins, p.ID)
p.Enabled = !disabled p.Enabled = !disabled
ret = append(ret, p) ret = append(ret, p)
@ -276,7 +276,7 @@ func (c Cache) executePostHooks(ctx context.Context, hookType HookTriggerEnum, h
hooks := p.getHooks(hookType) hooks := p.getHooks(hookType)
// don't revisit a plugin we've already visited // don't revisit a plugin we've already visited
// only log if there's hooks that we're skipping // only log if there's hooks that we're skipping
if len(hooks) > 0 && stringslice.StrInclude(visitedPlugins, p.id) { if len(hooks) > 0 && sliceutil.Contains(visitedPlugins, p.id) {
logger.Debugf("plugin ID '%s' already triggered, not re-triggering", p.id) logger.Debugf("plugin ID '%s' already triggered, not re-triggering", p.id)
continue continue
} }

View file

@ -10,7 +10,7 @@ import (
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/models/json" "github.com/stashapp/stash/pkg/models/json"
"github.com/stashapp/stash/pkg/models/jsonschema" "github.com/stashapp/stash/pkg/models/jsonschema"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/utils" "github.com/stashapp/stash/pkg/utils"
) )
@ -125,7 +125,7 @@ func GetDependentTagIDs(ctx context.Context, tags TagFinder, markerReader models
} }
for _, tt := range t { for _, tt := range t {
ret = intslice.IntAppendUnique(ret, tt.ID) ret = sliceutil.AppendUnique(ret, tt.ID)
} }
sm, err := markerReader.FindBySceneID(ctx, scene.ID) sm, err := markerReader.FindBySceneID(ctx, scene.ID)
@ -134,14 +134,14 @@ func GetDependentTagIDs(ctx context.Context, tags TagFinder, markerReader models
} }
for _, smm := range sm { for _, smm := range sm {
ret = intslice.IntAppendUnique(ret, smm.PrimaryTagID) ret = sliceutil.AppendUnique(ret, smm.PrimaryTagID)
smmt, err := tags.FindBySceneMarkerID(ctx, smm.ID) smmt, err := tags.FindBySceneMarkerID(ctx, smm.ID)
if err != nil { if err != nil {
return nil, fmt.Errorf("invalid tags for scene marker: %v", err) return nil, fmt.Errorf("invalid tags for scene marker: %v", err)
} }
for _, smmtt := range smmt { for _, smmtt := range smmt {
ret = intslice.IntAppendUnique(ret, smmtt.ID) ret = sliceutil.AppendUnique(ret, smmtt.ID)
} }
} }

View file

@ -7,7 +7,7 @@ import (
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/models/jsonschema" "github.com/stashapp/stash/pkg/models/jsonschema"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/utils" "github.com/stashapp/stash/pkg/utils"
) )
@ -246,8 +246,8 @@ func (i *Importer) populatePerformers(ctx context.Context) error {
pluckedNames = append(pluckedNames, performer.Name) pluckedNames = append(pluckedNames, performer.Name)
} }
missingPerformers := stringslice.StrFilter(names, func(name string) bool { missingPerformers := sliceutil.Filter(names, func(name string) bool {
return !stringslice.StrInclude(pluckedNames, name) return !sliceutil.Contains(pluckedNames, name)
}) })
if len(missingPerformers) > 0 { if len(missingPerformers) > 0 {
@ -442,8 +442,8 @@ func importTags(ctx context.Context, tagWriter models.TagFinderCreator, names []
pluckedNames = append(pluckedNames, tag.Name) pluckedNames = append(pluckedNames, tag.Name)
} }
missingTags := stringslice.StrFilter(names, func(name string) bool { missingTags := sliceutil.Filter(names, func(name string) bool {
return !stringslice.StrInclude(pluckedNames, name) return !sliceutil.Contains(pluckedNames, name)
}) })
if len(missingTags) > 0 { if len(missingTags) > 0 {

View file

@ -9,16 +9,16 @@ import (
"github.com/stashapp/stash/pkg/fsutil" "github.com/stashapp/stash/pkg/fsutil"
"github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/txn" "github.com/stashapp/stash/pkg/txn"
) )
func (s *Service) Merge(ctx context.Context, sourceIDs []int, destinationID int, scenePartial models.ScenePartial) error { func (s *Service) Merge(ctx context.Context, sourceIDs []int, destinationID int, scenePartial models.ScenePartial) error {
// ensure source ids are unique // ensure source ids are unique
sourceIDs = intslice.IntAppendUniques(nil, sourceIDs) sourceIDs = sliceutil.AppendUniques(nil, sourceIDs)
// ensure destination is not in source list // ensure destination is not in source list
if intslice.IntInclude(sourceIDs, destinationID) { if sliceutil.Contains(sourceIDs, destinationID) {
return errors.New("destination scene cannot be in source list") return errors.New("destination scene cannot be in source list")
} }

View file

@ -16,7 +16,7 @@ import (
"github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
type mappedQuery interface { type mappedQuery interface {
@ -730,8 +730,8 @@ func (c mappedScraperAttrConfig) concatenateResults(nodes []string) string {
} }
func (c mappedScraperAttrConfig) cleanResults(nodes []string) []string { func (c mappedScraperAttrConfig) cleanResults(nodes []string) []string {
cleaned := stringslice.StrUnique(nodes) // remove duplicate values cleaned := sliceutil.Unique(nodes) // remove duplicate values
cleaned = stringslice.StrDelete(cleaned, "") // remove empty values cleaned = sliceutil.Delete(cleaned, "") // remove empty values
return cleaned return cleaned
} }

View file

@ -8,7 +8,7 @@ import (
"github.com/gorilla/securecookie" "github.com/gorilla/securecookie"
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
"github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
type key int type key int
@ -179,7 +179,7 @@ func GetVisitedPlugins(ctx context.Context) []string {
func AddVisitedPlugin(ctx context.Context, pluginID string) context.Context { func AddVisitedPlugin(ctx context.Context, pluginID string) context.Context {
curVal := GetVisitedPlugins(ctx) curVal := GetVisitedPlugins(ctx)
curVal = stringslice.StrAppendUnique(curVal, pluginID) curVal = sliceutil.AppendUnique(curVal, pluginID)
return setVisitedPlugins(ctx, curVal) return setVisitedPlugins(ctx, curVal)
} }

View file

@ -1,20 +1,7 @@
package sliceutil package sliceutil
import "reflect" // Index returns the first index of the provided value in the provided
// slice. It returns -1 if it is not found.
// Exclude removes all instances of any value in toExclude from the vs
// slice. It returns the new or unchanged slice.
func Exclude[T comparable](vs []T, toExclude []T) []T {
var ret []T
for _, v := range vs {
if !Include(toExclude, v) {
ret = append(ret, v)
}
}
return ret
}
func Index[T comparable](vs []T, t T) int { func Index[T comparable](vs []T, t T) int {
for i, v := range vs { for i, v := range vs {
if v == t { if v == t {
@ -24,23 +11,24 @@ func Index[T comparable](vs []T, t T) int {
return -1 return -1
} }
func Include[T comparable](vs []T, t T) bool { // Contains returns whether the vs slice contains t.
func Contains[T comparable](vs []T, t T) bool {
return Index(vs, t) >= 0 return Index(vs, t) >= 0
} }
// IntAppendUnique appends toAdd to the vs int slice if toAdd does not already // AppendUnique appends toAdd to the vs slice if toAdd does not already
// exist in the slice. It returns the new or unchanged int slice. // exist in the slice. It returns the new or unchanged slice.
func AppendUnique[T comparable](vs []T, toAdd T) []T { func AppendUnique[T comparable](vs []T, toAdd T) []T {
if Include(vs, toAdd) { if Contains(vs, toAdd) {
return vs return vs
} }
return append(vs, toAdd) return append(vs, toAdd)
} }
// IntAppendUniques appends a slice of values to the vs slice. It only // AppendUniques appends a slice of values to the vs slice. It only
// appends values that do not already exist in the slice. It returns the new or // appends values that do not already exist in the slice.
// unchanged slice. // It returns the new or unchanged slice.
func AppendUniques[T comparable](vs []T, toAdd []T) []T { func AppendUniques[T comparable](vs []T, toAdd []T) []T {
for _, v := range toAdd { for _, v := range toAdd {
vs = AppendUnique(vs, v) vs = AppendUnique(vs, v)
@ -49,51 +37,90 @@ func AppendUniques[T comparable](vs []T, toAdd []T) []T {
return vs return vs
} }
// SliceSame returns true if the two provided lists have the same elements, // Exclude returns a copy of the vs slice, excluding all values
// regardless of order. Panics if either parameter is not a slice. // that are also present in the toExclude slice.
func SliceSame(a, b interface{}) bool { func Exclude[T comparable](vs []T, toExclude []T) []T {
v1 := reflect.ValueOf(a) var ret []T
v2 := reflect.ValueOf(b) for _, v := range vs {
if !Contains(toExclude, v) {
if (v1.IsValid() && v1.Kind() != reflect.Slice) || (v2.IsValid() && v2.Kind() != reflect.Slice) { ret = append(ret, v)
panic("not a slice") }
} }
v1Len := 0 return ret
v2Len := 0 }
v1Valid := v1.IsValid() // Unique returns a copy of the vs slice, with non-unique values removed.
v2Valid := v2.IsValid() func Unique[T comparable](vs []T) []T {
distinctValues := make(map[T]struct{})
if v1Valid { var ret []T
v1Len = v1.Len() for _, v := range vs {
if _, exists := distinctValues[v]; !exists {
distinctValues[v] = struct{}{}
ret = append(ret, v)
}
} }
if v2Valid { return ret
v2Len = v2.Len() }
// Delete returns a copy of the vs slice with toDel values removed.
func Delete[T comparable](vs []T, toDel T) []T {
var ret []T
for _, v := range vs {
if v != toDel {
ret = append(ret, v)
}
}
return ret
}
// Intersect returns a slice containing values that exist in both provided slices.
func Intersect[T comparable](a []T, b []T) []T {
var ret []T
for _, v := range a {
if Contains(b, v) {
ret = append(ret, v)
}
} }
if !v1Valid || !v2Valid { return ret
return v1Len == v2Len }
// NotIntersect returns a slice containing values that do not exist in both provided slices.
func NotIntersect[T comparable](a []T, b []T) []T {
var ret []T
for _, v := range a {
if !Contains(b, v) {
ret = append(ret, v)
}
} }
if v1Len != v2Len { for _, v := range b {
if !Contains(a, v) {
ret = append(ret, v)
}
}
return ret
}
// SliceSame returns true if the two provided slices have equal elements,
// regardless of order.
func SliceSame[T comparable](a []T, b []T) bool {
if len(a) != len(b) {
return false return false
} }
if v1.Type() != v2.Type() { visited := make(map[int]struct{})
return false for i := range a {
}
visited := make(map[int]bool)
for i := 0; i < v1.Len(); i++ {
found := false found := false
for j := 0; j < v2.Len(); j++ { for j := range b {
if visited[j] { if _, exists := visited[j]; exists {
continue continue
} }
if reflect.DeepEqual(v1.Index(i).Interface(), v2.Index(j).Interface()) { if a[i] == b[j] {
found = true found = true
visited[j] = true visited[j] = struct{}{}
break break
} }
} }
@ -105,3 +132,24 @@ func SliceSame(a, b interface{}) bool {
return true return true
} }
// Filter returns a slice containing the elements of the vs slice
// that meet the condition specified by f.
func Filter[T any](vs []T, f func(T) bool) []T {
var ret []T
for _, v := range vs {
if f(v) {
ret = append(ret, v)
}
}
return ret
}
// Filter returns the result of applying f to each element of the vs slice.
func Map[T any, V any](vs []T, f func(T) V) []V {
ret := make([]V, len(vs))
for i, v := range vs {
ret[i] = f(v)
}
return ret
}

View file

@ -1,32 +1,21 @@
package sliceutil package sliceutil
import "testing" import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSliceSame(t *testing.T) { func TestSliceSame(t *testing.T) {
objs := []struct {
a string
b int
}{
{"1", 2},
{"1", 2},
{"2", 1},
}
tests := []struct { tests := []struct {
name string name string
a interface{} a []int
b interface{} b []int
want bool want bool
}{ }{
{"nil values", nil, nil, true}, {"nil values", nil, nil, true},
{"empty", []int{}, []int{}, true}, {"empty", []int{}, []int{}, true},
{"nil and empty", nil, []int{}, true}, {"nil and empty", nil, []int{}, true},
{
"different type",
[]string{"1"},
[]int{1},
false,
},
{ {
"different length", "different length",
[]int{1, 2, 3}, []int{1, 2, 3},
@ -69,24 +58,11 @@ func TestSliceSame(t *testing.T) {
[]int{1, 1, 2, 2, 3}, []int{1, 1, 2, 2, 3},
false, false,
}, },
{
"structs equal",
objs[0:1],
objs[0:1],
true,
},
{
"structs not equal",
objs[0:2],
objs[1:3],
false,
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if got := SliceSame(tt.a, tt.b); got != tt.want { got := SliceSame(tt.a, tt.b)
t.Errorf("SliceSame() = %v, want %v", got, tt.want) assert.Equal(t, tt.want, got)
}
}) })
} }
} }

View file

@ -2,87 +2,6 @@ package intslice
import "strconv" import "strconv"
// IntIndex returns the first index of the provided int value in the provided
// int slice. It returns -1 if it is not found.
func IntIndex(vs []int, t int) int {
for i, v := range vs {
if v == t {
return i
}
}
return -1
}
// IntInclude returns true if the provided int value exists in the provided int
// slice.
func IntInclude(vs []int, t int) bool {
return IntIndex(vs, t) >= 0
}
// IntAppendUnique appends toAdd to the vs int slice if toAdd does not already
// exist in the slice. It returns the new or unchanged int slice.
func IntAppendUnique(vs []int, toAdd int) []int {
if IntInclude(vs, toAdd) {
return vs
}
return append(vs, toAdd)
}
// IntAppendUniques appends a slice of int values to the vs int slice. It only
// appends values that do not already exist in the slice. It returns the new or
// unchanged int slice.
func IntAppendUniques(vs []int, toAdd []int) []int {
for _, v := range toAdd {
vs = IntAppendUnique(vs, v)
}
return vs
}
// IntExclude removes all instances of any value in toExclude from the vs int
// slice. It returns the new or unchanged int slice.
func IntExclude(vs []int, toExclude []int) []int {
var ret []int
for _, v := range vs {
if !IntInclude(toExclude, v) {
ret = append(ret, v)
}
}
return ret
}
// IntIntercect returns a slice of ints containing values that exist in both provided slices.
func IntIntercect(v1, v2 []int) []int {
var ret []int
for _, v := range v1 {
if IntInclude(v2, v) {
ret = append(ret, v)
}
}
return ret
}
// IntNotIntersect returns a slice of ints containing values that do not exist in both provided slices.
func IntNotIntersect(v1, v2 []int) []int {
var ret []int
for _, v := range v1 {
if !IntInclude(v2, v) {
ret = append(ret, v)
}
}
for _, v := range v2 {
if !IntInclude(v1, v) {
ret = append(ret, v)
}
}
return ret
}
// IntSliceToStringSlice converts a slice of ints to a slice of strings. // IntSliceToStringSlice converts a slice of ints to a slice of strings.
func IntSliceToStringSlice(ss []int) []string { func IntSliceToStringSlice(ss []int) []string {
ret := make([]string, len(ss)) ret := make([]string, len(ss))

View file

@ -5,97 +5,6 @@ import (
"strings" "strings"
) )
// https://gobyexample.com/collection-functions
func StrIndex(vs []string, t string) int {
for i, v := range vs {
if v == t {
return i
}
}
return -1
}
func StrInclude(vs []string, t string) bool {
return StrIndex(vs, t) >= 0
}
func StrFilter(vs []string, f func(string) bool) []string {
vsf := make([]string, 0)
for _, v := range vs {
if f(v) {
vsf = append(vsf, v)
}
}
return vsf
}
func StrMap(vs []string, f func(string) string) []string {
vsm := make([]string, len(vs))
for i, v := range vs {
vsm[i] = f(v)
}
return vsm
}
// StrAppendUnique appends toAdd to the vs string slice if toAdd does not already
// exist in the slice. It returns the new or unchanged string slice.
func StrAppendUnique(vs []string, toAdd string) []string {
if StrInclude(vs, toAdd) {
return vs
}
return append(vs, toAdd)
}
// StrAppendUniques appends a slice of string values to the vs string slice. It only
// appends values that do not already exist in the slice. It returns the new or
// unchanged string slice.
func StrAppendUniques(vs []string, toAdd []string) []string {
for _, v := range toAdd {
vs = StrAppendUnique(vs, v)
}
return vs
}
// StrExclude removes all instances of any value in toExclude from the vs string
// slice. It returns the new or unchanged string slice.
func StrExclude(vs []string, toExclude []string) []string {
var ret []string
for _, v := range vs {
if !StrInclude(toExclude, v) {
ret = append(ret, v)
}
}
return ret
}
// StrUnique returns the vs string slice with non-unique values removed.
func StrUnique(vs []string) []string {
distinctValues := make(map[string]struct{})
var ret []string
for _, v := range vs {
if _, exists := distinctValues[v]; !exists {
distinctValues[v] = struct{}{}
ret = append(ret, v)
}
}
return ret
}
// StrDelete returns the vs string slice with toDel values removed.
func StrDelete(vs []string, toDel string) []string {
var ret []string
for _, v := range vs {
if v != toDel {
ret = append(ret, v)
}
}
return ret
}
// StringSliceToIntSlice converts a slice of strings to a slice of ints. // StringSliceToIntSlice converts a slice of strings to a slice of ints.
// Returns an error if any values cannot be parsed. // Returns an error if any values cannot be parsed.
func StringSliceToIntSlice(ss []string) ([]int, error) { func StringSliceToIntSlice(ss []string) ([]int, error) {

View file

@ -12,7 +12,7 @@ import (
"github.com/doug-martin/goqu/v9/exp" "github.com/doug-martin/goqu/v9/exp"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"gopkg.in/guregu/null.v4" "gopkg.in/guregu/null.v4"
"gopkg.in/guregu/null.v4/zero" "gopkg.in/guregu/null.v4/zero"
) )
@ -343,7 +343,7 @@ func (qb *GalleryStore) FindMany(ctx context.Context, ids []int) ([]*models.Gall
} }
for _, s := range unsorted { for _, s := range unsorted {
i := intslice.IntIndex(ids, s.ID) i := sliceutil.Index(ids, s.ID)
galleries[i] = s galleries[i] = s
} }

View file

@ -11,7 +11,7 @@ import (
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
const ( const (
@ -162,7 +162,7 @@ func (qb *GalleryChapterStore) FindMany(ctx context.Context, ids []int) ([]*mode
} }
for _, s := range unsorted { for _, s := range unsorted {
i := intslice.IntIndex(ids, s.ID) i := sliceutil.Index(ids, s.ID)
ret[i] = s ret[i] = s
} }

View file

@ -9,7 +9,7 @@ import (
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"gopkg.in/guregu/null.v4" "gopkg.in/guregu/null.v4"
"gopkg.in/guregu/null.v4/zero" "gopkg.in/guregu/null.v4/zero"
@ -323,7 +323,7 @@ func (qb *ImageStore) FindMany(ctx context.Context, ids []int) ([]*models.Image,
} }
for _, s := range unsorted { for _, s := range unsorted {
i := intslice.IntIndex(ids, s.ID) i := sliceutil.Index(ids, s.ID)
images[i] = s images[i] = s
} }

View file

@ -10,7 +10,7 @@ import (
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/sqlite" "github.com/stashapp/stash/pkg/sqlite"
) )
@ -136,7 +136,7 @@ func (m *schema42Migrator) migratePerformerAliases(id int, aliases string) error
} }
// remove duplicates // remove duplicates
aliasList = stringslice.StrAppendUniques(nil, aliasList) aliasList = sliceutil.AppendUniques(nil, aliasList)
// insert aliases into table // insert aliases into table
for _, alias := range aliasList { for _, alias := range aliasList {

View file

@ -13,7 +13,7 @@ import (
"gopkg.in/guregu/null.v4/zero" "gopkg.in/guregu/null.v4/zero"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
const ( const (
@ -204,7 +204,7 @@ func (qb *MovieStore) FindMany(ctx context.Context, ids []int) ([]*models.Movie,
} }
for _, s := range unsorted { for _, s := range unsorted {
i := intslice.IntIndex(ids, s.ID) i := sliceutil.Index(ids, s.ID)
ret[i] = s ret[i] = s
} }

View file

@ -12,7 +12,7 @@ import (
"github.com/doug-martin/goqu/v9/exp" "github.com/doug-martin/goqu/v9/exp"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/utils" "github.com/stashapp/stash/pkg/utils"
"gopkg.in/guregu/null.v4" "gopkg.in/guregu/null.v4"
"gopkg.in/guregu/null.v4/zero" "gopkg.in/guregu/null.v4/zero"
@ -336,7 +336,7 @@ func (qb *PerformerStore) FindMany(ctx context.Context, ids []int) ([]*models.Pe
} }
for _, s := range unsorted { for _, s := range unsorted {
i := intslice.IntIndex(ids, s.ID) i := sliceutil.Index(ids, s.ID)
ret[i] = s ret[i] = s
} }

View file

@ -13,7 +13,7 @@ import (
"github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
const ( const (
@ -182,7 +182,7 @@ func (qb *SavedFilterStore) FindMany(ctx context.Context, ids []int, ignoreNotFo
} }
for _, s := range unsorted { for _, s := range unsorted {
i := intslice.IntIndex(ids, s.ID) i := sliceutil.Index(ids, s.ID)
ret[i] = s ret[i] = s
} }

View file

@ -18,7 +18,7 @@ import (
"gopkg.in/guregu/null.v4/zero" "gopkg.in/guregu/null.v4/zero"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/utils" "github.com/stashapp/stash/pkg/utils"
) )
@ -456,7 +456,7 @@ func (qb *SceneStore) FindMany(ctx context.Context, ids []int) ([]*models.Scene,
} }
for _, s := range unsorted { for _, s := range unsorted {
i := intslice.IntIndex(ids, s.ID) i := sliceutil.Index(ids, s.ID)
scenes[i] = s scenes[i] = s
} }
@ -1819,7 +1819,7 @@ func (qb *SceneStore) FindDuplicates(ctx context.Context, distance int, duration
var sceneIds []int var sceneIds []int
for _, strId := range strIds { for _, strId := range strIds {
if intId, err := strconv.Atoi(strId); err == nil { if intId, err := strconv.Atoi(strId); err == nil {
sceneIds = intslice.IntAppendUnique(sceneIds, intId) sceneIds = sliceutil.AppendUnique(sceneIds, intId)
} }
} }
// filter out // filter out

View file

@ -11,7 +11,7 @@ import (
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
const sceneMarkerTable = "scene_markers" const sceneMarkerTable = "scene_markers"
@ -171,7 +171,7 @@ func (qb *SceneMarkerStore) FindMany(ctx context.Context, ids []int) ([]*models.
} }
for _, s := range unsorted { for _, s := range unsorted {
i := intslice.IntIndex(ids, s.ID) i := sliceutil.Index(ids, s.ID)
ret[i] = s ret[i] = s
} }

View file

@ -9,7 +9,7 @@ import (
"testing" "testing"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/sliceutil/stringslice" "github.com/stashapp/stash/pkg/sliceutil/stringslice"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -112,7 +112,7 @@ func verifyIDs(t *testing.T, modifier models.CriterionModifier, values []int, re
case models.CriterionModifierNotEquals: case models.CriterionModifierNotEquals:
foundAll := true foundAll := true
for _, v := range values { for _, v := range values {
if !intslice.IntInclude(results, v) { if !sliceutil.Contains(results, v) {
foundAll = false foundAll = false
break break
} }

View file

@ -15,7 +15,7 @@ import (
"time" "time"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -2376,12 +2376,12 @@ func TestSceneQueryPath(t *testing.T) {
mustInclude := indexesToIDs(sceneIDs, tt.mustInclude) mustInclude := indexesToIDs(sceneIDs, tt.mustInclude)
mustExclude := indexesToIDs(sceneIDs, tt.mustExclude) mustExclude := indexesToIDs(sceneIDs, tt.mustExclude)
missing := intslice.IntExclude(mustInclude, got.IDs) missing := sliceutil.Exclude(mustInclude, got.IDs)
if len(missing) > 0 { if len(missing) > 0 {
t.Errorf("SceneStore.TestSceneQueryPath() missing expected IDs: %v", missing) t.Errorf("SceneStore.TestSceneQueryPath() missing expected IDs: %v", missing)
} }
notExcluded := intslice.IntIntercect(mustExclude, got.IDs) notExcluded := sliceutil.Intersect(mustExclude, got.IDs)
if len(notExcluded) > 0 { if len(notExcluded) > 0 {
t.Errorf("SceneStore.TestSceneQueryPath() expected IDs to be excluded: %v", notExcluded) t.Errorf("SceneStore.TestSceneQueryPath() expected IDs to be excluded: %v", notExcluded)
} }

View file

@ -15,7 +15,7 @@ import (
"time" "time"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/sqlite" "github.com/stashapp/stash/pkg/sqlite"
"github.com/stashapp/stash/pkg/txn" "github.com/stashapp/stash/pkg/txn"
@ -1506,7 +1506,7 @@ func getTagMarkerCount(id int) int {
count := 0 count := 0
idx := indexFromID(tagIDs, id) idx := indexFromID(tagIDs, id)
for _, s := range markerSpecs { for _, s := range markerSpecs {
if s.primaryTagIdx == idx || intslice.IntInclude(s.tagIdxs, idx) { if s.primaryTagIdx == idx || sliceutil.Contains(s.tagIdxs, idx) {
count++ count++
} }
} }

View file

@ -13,7 +13,7 @@ import (
"gopkg.in/guregu/null.v4/zero" "gopkg.in/guregu/null.v4/zero"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/studio" "github.com/stashapp/stash/pkg/studio"
) )
@ -240,7 +240,7 @@ func (qb *StudioStore) FindMany(ctx context.Context, ids []int) ([]*models.Studi
} }
for _, s := range unsorted { for _, s := range unsorted {
i := intslice.IntIndex(ids, s.ID) i := sliceutil.Index(ids, s.ID)
ret[i] = s ret[i] = s
} }

View file

@ -14,8 +14,6 @@ import (
"github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/sliceutil/intslice"
"github.com/stashapp/stash/pkg/sliceutil/stringslice"
) )
type table struct { type table struct {
@ -202,7 +200,7 @@ func (t *joinTable) insertJoins(ctx context.Context, id int, foreignIDs []int) e
defer stmt.Close() defer stmt.Close()
// eliminate duplicates // eliminate duplicates
foreignIDs = intslice.IntAppendUniques(nil, foreignIDs) foreignIDs = sliceutil.AppendUniques(nil, foreignIDs)
for _, fk := range foreignIDs { for _, fk := range foreignIDs {
if _, err := tx.ExecStmt(ctx, stmt, id, fk); err != nil { if _, err := tx.ExecStmt(ctx, stmt, id, fk); err != nil {
@ -229,7 +227,7 @@ func (t *joinTable) addJoins(ctx context.Context, id int, foreignIDs []int) erro
} }
// only add foreign keys that are not already present // only add foreign keys that are not already present
foreignIDs = intslice.IntExclude(foreignIDs, fks) foreignIDs = sliceutil.Exclude(foreignIDs, fks)
return t.insertJoins(ctx, id, foreignIDs) return t.insertJoins(ctx, id, foreignIDs)
} }
@ -440,7 +438,7 @@ func (t *stringTable) addJoins(ctx context.Context, id int, v []string) error {
} }
// only add values that are not already present // only add values that are not already present
filtered := stringslice.StrExclude(v, existing) filtered := sliceutil.Exclude(v, existing)
return t.insertJoins(ctx, id, filtered) return t.insertJoins(ctx, id, filtered)
} }

View file

@ -14,7 +14,7 @@ import (
"gopkg.in/guregu/null.v4/zero" "gopkg.in/guregu/null.v4/zero"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
const ( const (
@ -205,7 +205,7 @@ func (qb *TagStore) FindMany(ctx context.Context, ids []int) ([]*models.Tag, err
} }
for _, s := range unsorted { for _, s := range unsorted {
i := intslice.IntIndex(ids, s.ID) i := sliceutil.Index(ids, s.ID)
ret[i] = s ret[i] = s
} }

View file

@ -5,7 +5,7 @@ import (
"strconv" "strconv"
"github.com/corona10/goimagehash" "github.com/corona10/goimagehash"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
) )
type Phash struct { type Phash struct {
@ -58,7 +58,7 @@ func findNeighbors(bucket int, neighbors []int, hashes []*Phash, scenes *[]int)
hash := hashes[id] hash := hashes[id]
if hash.Bucket == -1 { if hash.Bucket == -1 {
hash.Bucket = bucket hash.Bucket = bucket
*scenes = intslice.IntAppendUnique(*scenes, hash.SceneID) *scenes = sliceutil.AppendUnique(*scenes, hash.SceneID)
findNeighbors(bucket, hash.Neighbors, hashes, scenes) findNeighbors(bucket, hash.Neighbors, hashes, scenes)
} }
} }

View file

@ -21,7 +21,7 @@ import (
"github.com/stashapp/stash/pkg/fsutil" "github.com/stashapp/stash/pkg/fsutil"
"github.com/stashapp/stash/pkg/hash/md5" "github.com/stashapp/stash/pkg/hash/md5"
"github.com/stashapp/stash/pkg/models" "github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil/intslice" "github.com/stashapp/stash/pkg/sliceutil"
"github.com/stashapp/stash/pkg/sqlite" "github.com/stashapp/stash/pkg/sqlite"
"github.com/stashapp/stash/pkg/txn" "github.com/stashapp/stash/pkg/txn"
) )
@ -554,7 +554,7 @@ func makeMarkers(n int) {
tags := getRandomTags(ctx, 0, 5) tags := getRandomTags(ctx, 0, 5)
// remove primary tag // remove primary tag
tags = intslice.IntExclude(tags, []int{marker.PrimaryTagID}) tags = sliceutil.Exclude(tags, []int{marker.PrimaryTagID})
if err := repo.SceneMarker.UpdateTags(ctx, created.ID, tags); err != nil { if err := repo.SceneMarker.UpdateTags(ctx, created.ID, tags); err != nil {
return err return err
} }
@ -642,12 +642,12 @@ func getRandomPerformers(ctx context.Context) []int {
// } // }
// for _, pp := range p { // for _, pp := range p {
// ret = intslice.IntAppendUnique(ret, pp.ID) // ret = sliceutil.AppendUnique(ret, pp.ID)
// } // }
// } // }
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
ret = intslice.IntAppendUnique(ret, rand.Intn(c.Performers)+1) ret = sliceutil.AppendUnique(ret, rand.Intn(c.Performers)+1)
} }
return ret return ret
@ -677,12 +677,12 @@ func getRandomTags(ctx context.Context, min, max int) []int {
// } // }
// for _, tt := range t { // for _, tt := range t {
// ret = intslice.IntAppendUnique(ret, tt.ID) // ret = sliceutil.AppendUnique(ret, tt.ID)
// } // }
// } // }
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
ret = intslice.IntAppendUnique(ret, rand.Intn(c.Tags)+1) ret = sliceutil.AppendUnique(ret, rand.Intn(c.Tags)+1)
} }
return ret return ret
@ -699,12 +699,12 @@ func getRandomImages(ctx context.Context) []int {
// } // }
// for _, tt := range t { // for _, tt := range t {
// ret = intslice.IntAppendUnique(ret, tt.ID) // ret = sliceutil.AppendUnique(ret, tt.ID)
// } // }
// } // }
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
ret = intslice.IntAppendUnique(ret, rand.Intn(c.Images)+1) ret = sliceutil.AppendUnique(ret, rand.Intn(c.Images)+1)
} }
return ret return ret