Skip to content

Commit

Permalink
Add query filters for scenes with submitted fingerprints (stashapp#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
InfiniteStash authored and Maista6969 committed Jun 24, 2023
1 parent 47b59b9 commit 141c11f
Show file tree
Hide file tree
Showing 10 changed files with 347 additions and 35 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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 @@ -1386,6 +1390,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

0 comments on commit 141c11f

Please sign in to comment.