Add sorting by performer age (#6009)

This commit is contained in:
BigBangClock2
2025-11-09 23:49:40 +00:00
committed by GitHub
parent 638ebfc319
commit 1a9a62eae9
3 changed files with 32 additions and 0 deletions

View File

@@ -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)

View File

@@ -4131,6 +4131,13 @@ func TestSceneQuerySorting(t *testing.T) {
sceneIDs[sceneIdx1WithPerformer],
-1,
},
{
"performer_age",
"performer_age",
models.SortDirectionEnumDesc,
-1,
-1,
},
}
qb := db.Scene

View File

@@ -53,6 +53,7 @@ const sortByOptions = [
"interactive",
"interactive_speed",
"perceptual_similarity",
"performer_age",
"studio",
...MediaSortByOptions,
]