mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Add O-Counter for Performers and Sort/Filter Performers by O-Counter (#3588)
* initial commit of sort performer by o-count * work on o_counter filter * filter working * sorting, filtering using combined scene+image count * linting * fix performer list view --------- Co-authored-by: jpnsfw <none@none.com>
This commit is contained in:
@@ -103,6 +103,27 @@ func getCountSort(primaryTable, joinTable, primaryFK, direction string) string {
|
||||
return fmt.Sprintf(" ORDER BY (SELECT COUNT(*) FROM %s WHERE %s = %s.id) %s", joinTable, primaryFK, primaryTable, getSortDirection(direction))
|
||||
}
|
||||
|
||||
func getMultiSumSort(sum string, primaryTable, foreignTable1, joinTable1, foreignTable2, joinTable2, primaryFK, foreignFK1, foreignFK2, direction string) string {
|
||||
return fmt.Sprintf(" ORDER BY (SELECT SUM(%s) "+
|
||||
"FROM ("+
|
||||
"SELECT SUM(%s) as %s from %s s "+
|
||||
"LEFT JOIN %s ON %s.id = s.%s "+
|
||||
"WHERE s.%s = %s.id "+
|
||||
"UNION ALL "+
|
||||
"SELECT SUM(%s) as %s from %s s "+
|
||||
"LEFT JOIN %s ON %s.id = s.%s "+
|
||||
"WHERE s.%s = %s.id "+
|
||||
")) %s",
|
||||
sum,
|
||||
sum, sum, joinTable1,
|
||||
foreignTable1, foreignTable1, foreignFK1,
|
||||
primaryFK, primaryTable,
|
||||
sum, sum, joinTable2,
|
||||
foreignTable2, foreignTable2, foreignFK2,
|
||||
primaryFK, primaryTable,
|
||||
getSortDirection(direction))
|
||||
}
|
||||
|
||||
func getStringSearchClause(columns []string, q string, not bool) sqlClause {
|
||||
var likeClauses []string
|
||||
var args []interface{}
|
||||
@@ -287,6 +308,28 @@ func getCountCriterionClause(primaryTable, joinTable, primaryFK string, criterio
|
||||
return getIntCriterionWhereClause(lhs, criterion)
|
||||
}
|
||||
|
||||
func getJoinedMultiSumCriterionClause(primaryTable, foreignTable1, joinTable1, foreignTable2, joinTable2, primaryFK string, foreignFK1 string, foreignFK2 string, sum string, criterion models.IntCriterionInput) (string, []interface{}) {
|
||||
lhs := fmt.Sprintf("(SELECT SUM(%s) "+
|
||||
"FROM ("+
|
||||
"SELECT SUM(%s) as %s from %s s "+
|
||||
"LEFT JOIN %s ON %s.id = s.%s "+
|
||||
"WHERE s.%s = %s.id "+
|
||||
"UNION ALL "+
|
||||
"SELECT SUM(%s) as %s from %s s "+
|
||||
"LEFT JOIN %s ON %s.id = s.%s "+
|
||||
"WHERE s.%s = %s.id "+
|
||||
"))",
|
||||
sum,
|
||||
sum, sum, joinTable1,
|
||||
foreignTable1, foreignTable1, foreignFK1,
|
||||
primaryFK, primaryTable,
|
||||
sum, sum, joinTable2,
|
||||
foreignTable2, foreignTable2, foreignFK2,
|
||||
primaryFK, primaryTable,
|
||||
)
|
||||
return getIntCriterionWhereClause(lhs, criterion)
|
||||
}
|
||||
|
||||
func coalesce(column string) string {
|
||||
return fmt.Sprintf("COALESCE(%s, '')", column)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user