mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
* Restructure data layer part 2 (#2599) * Refactor and separate image model * Refactor image query builder * Handle relationships in image query builder * Remove relationship management methods * Refactor gallery model/query builder * Add scenes to gallery model * Convert scene model * Refactor scene models * Remove unused methods * Add unit tests for gallery * Add image tests * Add scene tests * Convert unnecessary scene value pointers to values * Convert unnecessary pointer values to values * Refactor scene partial * Add scene partial tests * Refactor ImagePartial * Add image partial tests * Refactor gallery partial update * Add partial gallery update tests * Use zero/null package for null values * Add files and scan system * Add sqlite implementation for files/folders * Add unit tests for files/folders * Image refactors * Update image data layer * Refactor gallery model and creation * Refactor scene model * Refactor scenes * Don't set title from filename * Allow galleries to freely add/remove images * Add multiple scene file support to graphql and UI * Add multiple file support for images in graphql/UI * Add multiple file for galleries in graphql/UI * Remove use of some deprecated fields * Remove scene path usage * Remove gallery path usage * Remove path from image * Move funscript to video file * Refactor caption detection * Migrate existing data * Add post commit/rollback hook system * Lint. Comment out import/export tests * Add WithDatabase read only wrapper * Prepend tasks to list * Add 32 pre-migration * Add warnings in release and migration notes
77 lines
1.7 KiB
Go
77 lines
1.7 KiB
Go
package intslice
|
|
|
|
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
|
|
}
|
|
|
|
// IntSliceToStringSlice converts a slice of ints to a slice of strings.
|
|
func IntSliceToStringSlice(ss []int) []string {
|
|
ret := make([]string, len(ss))
|
|
for i, v := range ss {
|
|
ret[i] = strconv.Itoa(v)
|
|
}
|
|
|
|
return ret
|
|
}
|