diff --git a/api/resolver.go b/api/resolver.go index 8109c0519..2d78f5ad1 100644 --- a/api/resolver.go +++ b/api/resolver.go @@ -85,19 +85,23 @@ func (r *queryResolver) ValidGalleriesForScene(ctx context.Context, scene_id *st } func (r *queryResolver) Stats(ctx context.Context) (models.StatsResultType, error) { - //scenesCount, _ := runCountQuery(buildCountQuery(selectAll("scenes")), nil) - //galleryCount, _ := runCountQuery(buildCountQuery(selectAll("galleries")), nil) - //performersCount, _ := runCountQuery(buildCountQuery(selectAll("performers")), nil) - //studiosCount, _ := runCountQuery(buildCountQuery(selectAll("studios")), nil) - //tagsCount, _ := runCountQuery(buildCountQuery(selectAll("tags")), nil) - //return StatsResultType{ - // SceneCount: scenesCount, - // GalleryCount: galleryCount, - // PerformerCount: performersCount, - // StudioCount: studiosCount, - // TagCount: tagsCount, - //}, nil - return models.StatsResultType{}, nil // TODO + scenesQB := models.NewSceneQueryBuilder() + scenesCount, _ := scenesQB.Count() + galleryQB := models.NewGalleryQueryBuilder() + galleryCount, _ := galleryQB.Count() + performersQB := models.NewPerformerQueryBuilder() + performersCount, _ := performersQB.Count() + studiosQB := models.NewStudioQueryBuilder() + studiosCount, _ := studiosQB.Count() + tagsQB := models.NewTagQueryBuilder() + tagsCount, _ := tagsQB.Count() + return models.StatsResultType{ + SceneCount: scenesCount, + GalleryCount: galleryCount, + PerformerCount: performersCount, + StudioCount: studiosCount, + TagCount: tagsCount, + }, nil } // Get scene marker tags which show up under the video. diff --git a/models/querybuilder_gallery.go b/models/querybuilder_gallery.go index 41c84dc90..f4168e618 100644 --- a/models/querybuilder_gallery.go +++ b/models/querybuilder_gallery.go @@ -80,6 +80,10 @@ func (qb *galleryQueryBuilder) ValidGalleriesForScenePath(scenePath string) ([]G return qb.queryGalleries(query, nil, nil) } +func (qb *galleryQueryBuilder) Count() (int, error) { + return runCountQuery(buildCountQuery("SELECT galleries.id FROM galleries"), nil) +} + func (qb *galleryQueryBuilder) All() ([]Gallery, error) { return qb.queryGalleries(selectAll("galleries") + qb.getGallerySort(nil), nil, nil) } diff --git a/models/querybuilder_performer.go b/models/querybuilder_performer.go index 1463b0b50..994cebfef 100644 --- a/models/querybuilder_performer.go +++ b/models/querybuilder_performer.go @@ -85,6 +85,10 @@ func (qb *performerQueryBuilder) FindByNames(names []string, tx *sqlx.Tx) ([]Per return qb.queryPerformers(query, args, tx) } +func (qb *performerQueryBuilder) Count() (int, error) { + return runCountQuery(buildCountQuery("SELECT performers.id FROM performers"), nil) +} + func (qb *performerQueryBuilder) All() ([]Performer, error) { return qb.queryPerformers(selectAll("performers") + qb.getPerformerSort(nil), nil, nil) } diff --git a/models/querybuilder_scene.go b/models/querybuilder_scene.go index df07242aa..21006292b 100644 --- a/models/querybuilder_scene.go +++ b/models/querybuilder_scene.go @@ -109,6 +109,10 @@ func (qb *sceneQueryBuilder) FindByStudioID(studioID int) ([]Scene, error) { return qb.queryScenes(scenesForStudioQuery, args, nil) } +func (qb *sceneQueryBuilder) Count() (int, error) { + return runCountQuery(buildCountQuery("SELECT scenes.id FROM scenes"), nil) +} + func (qb *sceneQueryBuilder) CountByStudioID(studioID int) (int, error) { args := []interface{}{studioID} return runCountQuery(buildCountQuery(scenesForStudioQuery), args) diff --git a/models/querybuilder_studio.go b/models/querybuilder_studio.go index c16ad7349..0c6f39deb 100644 --- a/models/querybuilder_studio.go +++ b/models/querybuilder_studio.go @@ -68,6 +68,10 @@ func (qb *studioQueryBuilder) FindByName(name string, tx *sqlx.Tx) (*Studio, err return qb.queryStudio(query, args, tx) } +func (qb *studioQueryBuilder) Count() (int, error) { + return runCountQuery(buildCountQuery("SELECT studios.id FROM studios"), nil) +} + func (qb *studioQueryBuilder) All() ([]Studio, error) { return qb.queryStudios(selectAll("studios") + qb.getStudioSort(nil), nil, nil) } diff --git a/models/querybuilder_tag.go b/models/querybuilder_tag.go index 02b93ca1a..a53d9eba7 100644 --- a/models/querybuilder_tag.go +++ b/models/querybuilder_tag.go @@ -102,6 +102,10 @@ func (qb *tagQueryBuilder) FindByNames(names []string, tx *sqlx.Tx) ([]Tag, erro return qb.queryTags(query, args, tx) } +func (qb *tagQueryBuilder) Count() (int, error) { + return runCountQuery(buildCountQuery("SELECT tags.id FROM tags"), nil) +} + func (qb *tagQueryBuilder) All() ([]Tag, error) { return qb.queryTags(selectAll("tags") + qb.getTagSort(nil), nil, nil) }