mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
Handle missing studio ids in getHierarchicalValues (#3845)
This commit is contained in:
parent
f440e06dc7
commit
cfc3912dcd
2 changed files with 27 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ package sqlite
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -950,13 +951,21 @@ WHERE id in {inBinding}
|
||||||
|
|
||||||
query := fmt.Sprintf("WITH RECURSIVE %s SELECT 'VALUES' || GROUP_CONCAT('(' || root_id || ', ' || item_id || ')') AS val FROM items", withClause)
|
query := fmt.Sprintf("WITH RECURSIVE %s SELECT 'VALUES' || GROUP_CONCAT('(' || root_id || ', ' || item_id || ')') AS val FROM items", withClause)
|
||||||
|
|
||||||
var valuesClause string
|
var valuesClause sql.NullString
|
||||||
err := tx.Get(ctx, &valuesClause, query, args...)
|
err := tx.Get(ctx, &valuesClause, query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to get hierarchical values: %w", err)
|
return "", fmt.Errorf("failed to get hierarchical values: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return valuesClause, nil
|
// if no values are found, just return a values string with the values only
|
||||||
|
if !valuesClause.Valid {
|
||||||
|
for i, value := range values {
|
||||||
|
values[i] = fmt.Sprintf("(%s, %s)", value, value)
|
||||||
|
}
|
||||||
|
valuesClause.String = "VALUES" + strings.Join(values, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
return valuesClause.String, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func addHierarchicalConditionClauses(f *filterBuilder, criterion models.HierarchicalMultiCriterionInput, table, idColumn string) {
|
func addHierarchicalConditionClauses(f *filterBuilder, criterion models.HierarchicalMultiCriterionInput, table, idColumn string) {
|
||||||
|
|
|
||||||
|
|
@ -2116,6 +2116,8 @@ func TestSceneQuery(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
endpoint = sceneStashID(sceneIdxWithGallery).Endpoint
|
endpoint = sceneStashID(sceneIdxWithGallery).Endpoint
|
||||||
stashID = sceneStashID(sceneIdxWithGallery).StashID
|
stashID = sceneStashID(sceneIdxWithGallery).StashID
|
||||||
|
|
||||||
|
depth = -1
|
||||||
)
|
)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
|
@ -2219,6 +2221,20 @@ func TestSceneQuery(t *testing.T) {
|
||||||
nil,
|
nil,
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"with studio id 0 including child studios",
|
||||||
|
nil,
|
||||||
|
&models.SceneFilterType{
|
||||||
|
Studios: &models.HierarchicalMultiCriterionInput{
|
||||||
|
Value: []string{"0"},
|
||||||
|
Modifier: models.CriterionModifierIncludes,
|
||||||
|
Depth: &depth,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue