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

Add query filters for scenes with submitted fingerprints #516

Merged
1 commit merged into from
Nov 7, 2022
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ generate-dataloaders:
go run github.com/vektah/dataloaden PerformerLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.Performer"; \
go run github.com/vektah/dataloaden ImageLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.Image"; \
go run github.com/vektah/dataloaden FingerprintsLoader github.com/gofrs/uuid.UUID "[]*github.com/stashapp/stash-box/pkg/models.Fingerprint"; \
go run github.com/vektah/dataloaden SubmittedFingerprintsLoader github.com/gofrs/uuid.UUID "[]*github.com/stashapp/stash-box/pkg/models.Fingerprint"; \
go run github.com/vektah/dataloaden BodyModificationsLoader github.com/gofrs/uuid.UUID "[]*github.com/stashapp/stash-box/pkg/models.BodyModification"; \
go run github.com/vektah/dataloaden TagCategoryLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.TagCategory"; \
go run github.com/vektah/dataloaden SiteLoader github.com/gofrs/uuid.UUID "*github.com/stashapp/stash-box/pkg/models.Site";
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,10 @@ export type Scene = {
urls: Array<Url>;
};

export type SceneFingerprintsArgs = {
is_submitted?: InputMaybe<Scalars["Boolean"]>;
};

export type SceneCreateInput = {
code?: InputMaybe<Scalars["String"]>;
date: Scalars["String"];
Expand Down Expand Up @@ -1382,6 +1386,8 @@ export type SceneQueryInput = {
favorites?: InputMaybe<FavoriteFilter>;
/** Filter to only include scenes with these fingerprints */
fingerprints?: InputMaybe<MultiStringCriterionInput>;
/** Filter to scenes with fingerprints submitted by the user */
has_fingerprint_submissions?: InputMaybe<Scalars["Boolean"]>;
page?: Scalars["Int"];
/** Filter to only include scenes with this studio as primary or parent */
parentStudio?: InputMaybe<Scalars["String"]>;
Expand Down
4 changes: 3 additions & 1 deletion graphql/schema/types/scene.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type Scene {
tags: [Tag!]!
images: [Image!]!
performers: [PerformerAppearance!]!
fingerprints: [Fingerprint!]!
fingerprints(is_submitted: Boolean = False): [Fingerprint!]!
duration: Int
director: String
code: String
Expand Down Expand Up @@ -209,6 +209,8 @@ input SceneQueryInput {
fingerprints: MultiStringCriterionInput
"""Filter by favorited entity"""
favorites: FavoriteFilter
"""Filter to scenes with fingerprints submitted by the user"""
has_fingerprint_submissions: Boolean = False

page: Int! = 1
per_page: Int! = 25
Expand Down
6 changes: 5 additions & 1 deletion pkg/api/resolver_model_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ func (r *sceneResolver) Performers(ctx context.Context, obj *models.Scene) ([]*m

return ret, nil
}
func (r *sceneResolver) Fingerprints(ctx context.Context, obj *models.Scene) ([]*models.Fingerprint, error) {

func (r *sceneResolver) Fingerprints(ctx context.Context, obj *models.Scene, isSubmitted *bool) ([]*models.Fingerprint, error) {
if isSubmitted != nil && *isSubmitted {
return dataloader.For(ctx).SubmittedSceneFingerprintsByID.Load(obj.ID)
}
return dataloader.For(ctx).SceneFingerprintsByID.Load(obj.ID)
}

Expand Down
47 changes: 28 additions & 19 deletions pkg/dataloader/loaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@ const (
)

type Loaders struct {
SceneFingerprintsByID FingerprintsLoader
ImageByID ImageLoader
PerformerByID PerformerLoader
PerformerAliasesByID StringsLoader
PerformerImageIDsByID UUIDsLoader
PerformerMergeIDsByID UUIDsLoader
PerformerPiercingsByID BodyModificationsLoader
PerformerTattoosByID BodyModificationsLoader
PerformerUrlsByID URLLoader
SceneImageIDsByID UUIDsLoader
SceneAppearancesByID SceneAppearancesLoader
SceneUrlsByID URLLoader
StudioImageIDsByID UUIDsLoader
StudioUrlsByID URLLoader
SceneTagIDsByID UUIDsLoader
SiteByID SiteLoader
TagByID TagLoader
TagCategoryByID TagCategoryLoader
SceneFingerprintsByID FingerprintsLoader
SubmittedSceneFingerprintsByID FingerprintsLoader
ImageByID ImageLoader
PerformerByID PerformerLoader
PerformerAliasesByID StringsLoader
PerformerImageIDsByID UUIDsLoader
PerformerMergeIDsByID UUIDsLoader
PerformerPiercingsByID BodyModificationsLoader
PerformerTattoosByID BodyModificationsLoader
PerformerUrlsByID URLLoader
SceneImageIDsByID UUIDsLoader
SceneAppearancesByID SceneAppearancesLoader
SceneUrlsByID URLLoader
StudioImageIDsByID UUIDsLoader
StudioUrlsByID URLLoader
SceneTagIDsByID UUIDsLoader
SiteByID SiteLoader
TagByID TagLoader
TagCategoryByID TagCategoryLoader
}

func Middleware(fac models.Repo) func(next http.Handler) http.Handler {
Expand Down Expand Up @@ -63,7 +64,15 @@ func GetLoaders(ctx context.Context, fac models.Repo) *Loaders {
wait: 1 * time.Millisecond,
fetch: func(ids []uuid.UUID) ([][]*models.Fingerprint, []error) {
qb := fac.Scene()
return qb.GetAllFingerprints(currentUser.ID, ids)
return qb.GetAllFingerprints(currentUser.ID, ids, false)
},
},
SubmittedSceneFingerprintsByID: FingerprintsLoader{
maxBatch: 100,
wait: 1 * time.Millisecond,
fetch: func(ids []uuid.UUID) ([][]*models.Fingerprint, []error) {
qb := fac.Scene()
return qb.GetAllFingerprints(currentUser.ID, ids, true)
},
},
PerformerByID: PerformerLoader{
Expand Down
226 changes: 226 additions & 0 deletions pkg/dataloader/submittedfingerprintsloader_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading