mirror of
https://github.com/stashapp/stash.git
synced 2025-12-16 20:07:05 +03:00
Add sorting by performer age (#6009)
This commit is contained in:
@@ -1100,6 +1100,7 @@ var sceneSortOptions = sortOptions{
|
||||
"tag_count",
|
||||
"title",
|
||||
"updated_at",
|
||||
"performer_age",
|
||||
}
|
||||
|
||||
func (qb *SceneStore) setSceneSort(query *queryBuilder, findFilter *models.FindFilterType) error {
|
||||
@@ -1209,6 +1210,29 @@ func (qb *SceneStore) setSceneSort(query *queryBuilder, findFilter *models.FindF
|
||||
query.sortAndPagination += fmt.Sprintf(" ORDER BY (SELECT MAX(o_date) FROM %s AS sort WHERE sort.%s = %s.id) %s", scenesODatesTable, sceneIDColumn, sceneTable, getSortDirection(direction))
|
||||
case "o_counter":
|
||||
query.sortAndPagination += getCountSort(sceneTable, scenesODatesTable, sceneIDColumn, direction)
|
||||
case "performer_age":
|
||||
// Looking at the youngest performer by default
|
||||
aggregation := "MIN"
|
||||
if direction == "DESC" {
|
||||
// When sorting by performer_'s age DESC, I should consider the oldest performer instead
|
||||
aggregation = "MAX"
|
||||
}
|
||||
fallback := "NULL"
|
||||
if direction == "ASC" {
|
||||
// When sorting ascending, NULLs are first by default. Coalescing to the MAX int value supported by sqlite
|
||||
fallback = "9223372036854775807"
|
||||
}
|
||||
query.sortAndPagination += fmt.Sprintf(
|
||||
" ORDER BY (SELECT COALESCE(%s(JulianDay(scenes.date) - JulianDay(performers.birthdate)), %s) FROM %s as performers INNER JOIN %s AS aggregation WHERE performers.id = aggregation.%s AND aggregation.%s = %s.id) %s",
|
||||
aggregation,
|
||||
fallback,
|
||||
performerTable,
|
||||
performersScenesTable,
|
||||
performerIDColumn,
|
||||
sceneIDColumn,
|
||||
sceneTable,
|
||||
getSortDirection(direction),
|
||||
)
|
||||
case "studio":
|
||||
query.join(studioTable, "", "scenes.studio_id = studios.id")
|
||||
query.sortAndPagination += getSort("name", direction, studioTable)
|
||||
|
||||
@@ -4131,6 +4131,13 @@ func TestSceneQuerySorting(t *testing.T) {
|
||||
sceneIDs[sceneIdx1WithPerformer],
|
||||
-1,
|
||||
},
|
||||
{
|
||||
"performer_age",
|
||||
"performer_age",
|
||||
models.SortDirectionEnumDesc,
|
||||
-1,
|
||||
-1,
|
||||
},
|
||||
}
|
||||
|
||||
qb := db.Scene
|
||||
|
||||
Reference in New Issue
Block a user