mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Add sorting by performer age (#6009)
This commit is contained in:
@@ -1100,6 +1100,7 @@ var sceneSortOptions = sortOptions{
|
|||||||
"tag_count",
|
"tag_count",
|
||||||
"title",
|
"title",
|
||||||
"updated_at",
|
"updated_at",
|
||||||
|
"performer_age",
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qb *SceneStore) setSceneSort(query *queryBuilder, findFilter *models.FindFilterType) error {
|
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))
|
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":
|
case "o_counter":
|
||||||
query.sortAndPagination += getCountSort(sceneTable, scenesODatesTable, sceneIDColumn, direction)
|
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":
|
case "studio":
|
||||||
query.join(studioTable, "", "scenes.studio_id = studios.id")
|
query.join(studioTable, "", "scenes.studio_id = studios.id")
|
||||||
query.sortAndPagination += getSort("name", direction, studioTable)
|
query.sortAndPagination += getSort("name", direction, studioTable)
|
||||||
|
|||||||
@@ -4131,6 +4131,13 @@ func TestSceneQuerySorting(t *testing.T) {
|
|||||||
sceneIDs[sceneIdx1WithPerformer],
|
sceneIDs[sceneIdx1WithPerformer],
|
||||||
-1,
|
-1,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"performer_age",
|
||||||
|
"performer_age",
|
||||||
|
models.SortDirectionEnumDesc,
|
||||||
|
-1,
|
||||||
|
-1,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
qb := db.Scene
|
qb := db.Scene
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ const sortByOptions = [
|
|||||||
"interactive",
|
"interactive",
|
||||||
"interactive_speed",
|
"interactive_speed",
|
||||||
"perceptual_similarity",
|
"perceptual_similarity",
|
||||||
|
"performer_age",
|
||||||
"studio",
|
"studio",
|
||||||
...MediaSortByOptions,
|
...MediaSortByOptions,
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user