Sort performers and studios by scenes file size (#6642)

* feat: add scenes_size sort option for performers

Adds sorting performers by total file size of associated scenes.
Follows the existing scenes_duration pattern.

Ref: stashapp/stash#5530

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add scenes_size sort option for studios

Adds sorting studios by total file size of associated scenes.
Follows the existing scenes_duration pattern.

Ref: stashapp/stash#5530

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(ui): add Scenes Size sort option for performers and studios

Adds 'Scenes Size' to the sort dropdown for performer and studio
list views, with i18n label.

Ref: stashapp/stash#5530

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: extend scenes_size sort to tags

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
dev-null-life 2026-03-17 19:51:56 -05:00 committed by GitHub
parent b2179cd723
commit f7b04fba61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 56 additions and 1 deletions

View file

@ -782,6 +782,28 @@ func (qb *PerformerStore) sortByScenesDuration(direction string) string {
return " ORDER BY (" + selectPerformerScenesDurationSQL + ") " + direction
}
// used for sorting by total scene file size
var selectPerformerScenesSizeSQL = utils.StrFormat(
"SELECT COALESCE(SUM({files}.size), 0) FROM {performers_scenes} s "+
"LEFT JOIN {scenes} ON {scenes}.id = s.{scene_id} "+
"LEFT JOIN {scenes_files} ON {scenes_files}.{scene_id} = {scenes}.id "+
"LEFT JOIN {files} ON {files}.id = {scenes_files}.file_id "+
"WHERE s.{performer_id} = {performers}.id",
map[string]interface{}{
"performer_id": performerIDColumn,
"performers": performerTable,
"performers_scenes": performersScenesTable,
"scenes": sceneTable,
"scene_id": sceneIDColumn,
"scenes_files": scenesFilesTable,
"files": fileTable,
},
)
func (qb *PerformerStore) sortByScenesSize(direction string) string {
return " ORDER BY (" + selectPerformerScenesSizeSQL + ") " + direction
}
var performerSortOptions = sortOptions{
"birthdate",
"career_start",
@ -803,6 +825,7 @@ var performerSortOptions = sortOptions{
"rating",
"scenes_count",
"scenes_duration",
"scenes_size",
"tag_count",
"updated_at",
"weight",
@ -832,6 +855,8 @@ func (qb *PerformerStore) getPerformerSort(findFilter *models.FindFilterType) (s
sortQuery += getCountSort(performerTable, performersScenesTable, performerIDColumn, direction)
case "scenes_duration":
sortQuery += qb.sortByScenesDuration(direction)
case "scenes_size":
sortQuery += qb.sortByScenesSize(direction)
case "images_count":
sortQuery += getCountSort(performerTable, performersImagesTable, performerIDColumn, direction)
case "galleries_count":

View file

@ -629,6 +629,16 @@ func (qb *StudioStore) sortByScenesDuration(direction string) string {
) %s`, sceneTable, scenesFilesTable, scenesFilesTable, sceneIDColumn, sceneTable, scenesFilesTable, sceneTable, studioIDColumn, studioTable, getSortDirection(direction))
}
func (qb *StudioStore) sortByScenesSize(direction string) string {
return fmt.Sprintf(` ORDER BY (
SELECT COALESCE(SUM(%s.size), 0)
FROM %s
LEFT JOIN %s ON %s.%s = %s.id
LEFT JOIN %s ON %s.id = %s.file_id
WHERE %s.%s = %s.id
) %s`, fileTable, sceneTable, scenesFilesTable, scenesFilesTable, sceneIDColumn, sceneTable, fileTable, fileTable, scenesFilesTable, sceneTable, studioIDColumn, studioTable, getSortDirection(direction))
}
// used for sorting on performer latest scene
var selectStudioLatestSceneSQL = utils.StrFormat(
"SELECT MAX(date) FROM ("+
@ -658,6 +668,7 @@ var studioSortOptions = sortOptions{
"name",
"scenes_count",
"scenes_duration",
"scenes_size",
"random",
"rating",
"tag_count",
@ -688,6 +699,8 @@ func (qb *StudioStore) getStudioSort(findFilter *models.FindFilterType) (string,
sortQuery += getCountSort(studioTable, sceneTable, studioIDColumn, direction)
case "scenes_duration":
sortQuery += qb.sortByScenesDuration(direction)
case "scenes_size":
sortQuery += qb.sortByScenesSize(direction)
case "images_count":
sortQuery += getCountSort(studioTable, imageTable, studioIDColumn, direction)
case "galleries_count":

View file

@ -770,6 +770,7 @@ var tagSortOptions = sortOptions{
"scene_markers_count",
"scenes_count",
"scenes_duration",
"scenes_size",
"updated_at",
}
@ -784,6 +785,17 @@ func (qb *TagStore) sortByScenesDuration(direction string) string {
) %s`, scenesTagsTable, sceneTable, sceneTable, scenesTagsTable, sceneIDColumn, scenesFilesTable, scenesFilesTable, sceneIDColumn, sceneTable, scenesFilesTable, scenesTagsTable, tagIDColumn, tagTable, getSortDirection(direction))
}
func (qb *TagStore) sortByScenesSize(direction string) string {
return fmt.Sprintf(` ORDER BY (
SELECT COALESCE(SUM(%s.size), 0)
FROM %s
LEFT JOIN %s ON %s.id = %s.%s
LEFT JOIN %s ON %s.%s = %s.id
LEFT JOIN %s ON %s.id = %s.file_id
WHERE %s.%s = %s.id
) %s`, fileTable, scenesTagsTable, sceneTable, sceneTable, scenesTagsTable, sceneIDColumn, scenesFilesTable, scenesFilesTable, sceneIDColumn, sceneTable, fileTable, fileTable, scenesFilesTable, scenesTagsTable, tagIDColumn, tagTable, getSortDirection(direction))
}
func (qb *TagStore) getDefaultTagSort() string {
return getSort("name", "ASC", "tags")
}
@ -812,6 +824,8 @@ func (qb *TagStore) getTagSort(query *queryBuilder, findFilter *models.FindFilte
sortQuery += getCountSort(tagTable, scenesTagsTable, tagIDColumn, direction)
case "scenes_duration":
sortQuery += qb.sortByScenesDuration(direction)
case "scenes_size":
sortQuery += qb.sortByScenesSize(direction)
case "scene_markers_count":
sortQuery += fmt.Sprintf(" ORDER BY (SELECT COUNT(*) FROM scene_markers_tags WHERE tags.id = scene_markers_tags.tag_id)+(SELECT COUNT(*) FROM scene_markers WHERE tags.id = scene_markers.primary_tag_id) %s", getSortDirection(direction))
case "images_count":

View file

@ -1400,6 +1400,7 @@
"scene_code": "Studio Code",
"scene_count": "Scene Count",
"scenes_duration": "Scene Duration",
"scenes_size": "Scene Size",
"scene_created_at": "Scene Created At",
"scene_date": "Date of Scene",
"scene_id": "Scene ID",

View file

@ -37,6 +37,7 @@ const sortByOptions = [
"weight",
"measurements",
"scenes_duration",
"scenes_size",
]
.map(ListFilterOptions.createSortBy)
.concat([

View file

@ -22,6 +22,7 @@ const sortByOptions = [
"random",
"rating",
"scenes_duration",
"scenes_size",
"latest_scene",
]
.map(ListFilterOptions.createSortBy)

View file

@ -18,7 +18,7 @@ import { StashIDCriterionOption } from "./criteria/stash-ids";
import { CustomFieldsCriterionOption } from "./criteria/custom-fields";
const defaultSortBy = "name";
const sortByOptions = ["name", "random", "scenes_duration"]
const sortByOptions = ["name", "random", "scenes_duration", "scenes_size"]
.map(ListFilterOptions.createSortBy)
.concat([
{