Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore image performer age filter #4601

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions graphql/schema/types/filters.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ input ImageFilterType {
performer_count: IntCriterionInput
"Filter images that have performers that have been favorited"
performer_favorite: Boolean
"Filter images by performer age at time of image"
performer_age: IntCriterionInput
"Filter to only include images with these galleries"
galleries: MultiCriterionInput
"Filter by creation time"
Expand Down
2 changes: 2 additions & 0 deletions pkg/models/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type ImageFilterType struct {
PerformerCount *IntCriterionInput `json:"performer_count"`
// Filter images that have performers that have been favorited
PerformerFavorite *bool `json:"performer_favorite"`
// Filter images by performer age at time of image
PerformerAge *IntCriterionInput `json:"performer_age"`
// Filter to only include images with these galleries
Galleries *MultiCriterionInput `json:"galleries"`
// Filter by created at
Expand Down
17 changes: 17 additions & 0 deletions pkg/sqlite/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ func (qb *ImageStore) makeFilter(ctx context.Context, imageFilter *models.ImageF
query.handleCriterion(ctx, studioCriterionHandler(imageTable, imageFilter.Studios))
query.handleCriterion(ctx, imagePerformerTagsCriterionHandler(qb, imageFilter.PerformerTags))
query.handleCriterion(ctx, imagePerformerFavoriteCriterionHandler(imageFilter.PerformerFavorite))
query.handleCriterion(ctx, imagePerformerAgeCriterionHandler(imageFilter.PerformerAge))
query.handleCriterion(ctx, timestampCriterionHandler(imageFilter.CreatedAt, "images.created_at"))
query.handleCriterion(ctx, timestampCriterionHandler(imageFilter.UpdatedAt, "images.updated_at"))

Expand Down Expand Up @@ -1025,6 +1026,22 @@ GROUP BY performers_images.image_id HAVING SUM(performers.favorite) = 0)`, "nofa
}
}

func imagePerformerAgeCriterionHandler(performerAge *models.IntCriterionInput) criterionHandlerFunc {
return func(ctx context.Context, f *filterBuilder) {
if performerAge != nil {
f.addInnerJoin("performers_images", "", "images.id = performers_images.image_id")
f.addInnerJoin("performers", "", "performers_images.performer_id = performers.id")

f.addWhere("images.date != '' AND performers.birthdate != ''")
f.addWhere("images.date IS NOT NULL AND performers.birthdate IS NOT NULL")

ageCalc := "cast(strftime('%Y.%m%d', images.date) - strftime('%Y.%m%d', performers.birthdate) as int)"
whereClause, args := getIntWhereClause(ageCalc, performerAge.Modifier, performerAge.Value, performerAge.Value2)
f.addWhere(whereClause, args...)
}
}
}

func imagePerformerTagsCriterionHandler(qb *ImageStore, tags *models.HierarchicalMultiCriterionInput) criterionHandler {
return &joinedPerformerTagsHandler{
criterion: tags,
Expand Down
1 change: 1 addition & 0 deletions ui/v2.5/src/models/list-filter/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const criterionOptions = [
PerformerTagsCriterionOption,
PerformersCriterionOption,
createMandatoryNumberCriterionOption("performer_count"),
createMandatoryNumberCriterionOption("performer_age"),
PerformerFavoriteCriterionOption,
StudiosCriterionOption,
createStringCriterionOption("url"),
Expand Down
Loading