Add group scene count filter (#6593)

This commit is contained in:
WithoutPants 2026-02-20 09:14:25 +11:00 committed by GitHub
parent c15e6a5b63
commit 843806247d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 42 additions and 0 deletions

View file

@ -455,6 +455,8 @@ input GroupFilterType {
containing_group_count: IntCriterionInput
"Filter by number of sub-groups the group has"
sub_group_count: IntCriterionInput
"Filter by number of scenes the group has"
scene_count: IntCriterionInput
"Filter by related scenes that meet this criteria"
scenes_filter: SceneFilterType

View file

@ -33,6 +33,8 @@ type GroupFilterType struct {
ContainingGroupCount *IntCriterionInput `json:"containing_group_count"`
// Filter by number of sub-groups the group has
SubGroupCount *IntCriterionInput `json:"sub_group_count"`
// Filter by number of scenes the group has
SceneCount *IntCriterionInput `json:"scene_count"`
// Filter by related scenes that meet this criteria
ScenesFilter *SceneFilterType `json:"scenes_filter"`
// Filter by related studios that meet this criteria

View file

@ -75,6 +75,7 @@ func (qb *groupFilterHandler) criterionHandler() criterionHandler {
qb.tagsCriterionHandler(groupFilter.Tags),
qb.tagCountCriterionHandler(groupFilter.TagCount),
qb.groupOCounterCriterionHandler(groupFilter.OCounter),
qb.sceneCountCriterionHandler(groupFilter.SceneCount),
&dateCriterionHandler{groupFilter.Date, "groups.date", nil},
groupHierarchyHandler.ParentsCriterionHandler(groupFilter.ContainingGroups),
groupHierarchyHandler.ChildrenCriterionHandler(groupFilter.SubGroups),
@ -204,6 +205,16 @@ func (qb *groupFilterHandler) tagCountCriterionHandler(count *models.IntCriterio
return h.handler(count)
}
func (qb *groupFilterHandler) sceneCountCriterionHandler(count *models.IntCriterionInput) criterionHandlerFunc {
h := countCriterionHandlerBuilder{
primaryTable: groupTable,
joinTable: groupsScenesTable,
primaryFK: groupIDColumn,
}
return h.handler(count)
}
// used for sorting and filtering on group o-count
var selectGroupOCountSQL = utils.StrFormat(
"SELECT SUM(o_counter) "+

View file

@ -669,6 +669,32 @@ func TestGroupQuery(t *testing.T) {
nil,
false,
},
{
"scene count equals 1",
nil,
&models.GroupFilterType{
SceneCount: &models.IntCriterionInput{
Value: 1,
Modifier: models.CriterionModifierEquals,
},
},
[]int{groupIdxWithScene},
[]int{groupIdxWithParentAndChild},
false,
},
{
"scene count less than 1",
nil,
&models.GroupFilterType{
SceneCount: &models.IntCriterionInput{
Value: 1,
Modifier: models.CriterionModifierLessThan,
},
},
[]int{groupIdxWithParentAndChild},
[]int{groupIdxWithScene},
false,
},
}
for _, tt := range tests {

View file

@ -63,6 +63,7 @@ const criterionOptions = [
createMandatoryNumberCriterionOption("sub_group_count"),
TagsCriterionOption,
createMandatoryNumberCriterionOption("tag_count"),
createMandatoryNumberCriterionOption("scene_count"),
createMandatoryTimestampCriterionOption("created_at"),
createMandatoryTimestampCriterionOption("updated_at"),
];