diff --git a/pkg/sqlite/filter.go b/pkg/sqlite/filter.go index cb8e56e97..1517bf99a 100644 --- a/pkg/sqlite/filter.go +++ b/pkg/sqlite/filter.go @@ -539,18 +539,27 @@ func addHierarchicalWithClause(f *filterBuilder, value []string, derivedTable, t depthCondition = fmt.Sprintf("WHERE depth < %d", depth) } - withClause := utils.StrFormat(`RECURSIVE {derivedTable} AS ( -SELECT id as id, id as child_id, 0 as depth FROM {table} -WHERE id in {inBinding} -UNION SELECT p.id, c.id, depth + 1 FROM {table} as c -INNER JOIN {derivedTable} as p ON c.{parentFK} = p.child_id {depthCondition}) -`, utils.StrFormatMap{ + withClauseMap := utils.StrFormatMap{ "derivedTable": derivedTable, "table": table, "inBinding": getInBinding(inCount), "parentFK": parentFK, "depthCondition": depthCondition, - }) + "unionClause": "", + } + + if depth != 0 { + withClauseMap["unionClause"] = utils.StrFormat(` +UNION SELECT p.id, c.id, depth + 1 FROM {table} as c +INNER JOIN {derivedTable} as p ON c.{parentFK} = p.child_id {depthCondition} +`, withClauseMap) + } + + withClause := utils.StrFormat(`RECURSIVE {derivedTable} AS ( +SELECT id as id, id as child_id, 0 as depth FROM {table} +WHERE id in {inBinding} +{unionClause}) +`, withClauseMap) f.addWith(withClause, args...) } diff --git a/ui/v2.5/src/components/Changelog/versions/v090.md b/ui/v2.5/src/components/Changelog/versions/v090.md index 51c28b421..69c23e827 100644 --- a/ui/v2.5/src/components/Changelog/versions/v090.md +++ b/ui/v2.5/src/components/Changelog/versions/v090.md @@ -19,6 +19,7 @@ * Added de-DE language option. ([#1578](https://github.com/stashapp/stash/pull/1578)) ### 🐛 Bug fixes +* Fix performance issue on Studios page getting studio image count. ([#1643](https://github.com/stashapp/stash/pull/1643)) * Regenerate scene phash if overwrite flag is set. ([#1633](https://github.com/stashapp/stash/pull/1633)) * Create .stash directory in $HOME only if required. ([#1623](https://github.com/stashapp/stash/pull/1623)) * Include stash id when scraping performer from stash-box. ([#1608](https://github.com/stashapp/stash/pull/1608))