mirror of https://github.com/stashapp/stash.git
Fix image querying (#2119)
* Fix image querying * Add unit tests Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
parent
d176e9f192
commit
b58883c074
|
@ -360,7 +360,7 @@ func imageIsMissingCriterionHandler(qb *imageQueryBuilder, isMissing *string) cr
|
|||
qb.performersRepository().join(f, "performers_join", "images.id")
|
||||
f.addWhere("performers_join.image_id IS NULL")
|
||||
case "galleries":
|
||||
qb.galleriesRepository().innerJoin(f, "galleries_join", "images.id")
|
||||
qb.galleriesRepository().join(f, "galleries_join", "images.id")
|
||||
f.addWhere("galleries_join.image_id IS NULL")
|
||||
case "tags":
|
||||
qb.tagsRepository().join(f, "tags_join", "images.id")
|
||||
|
@ -412,8 +412,8 @@ func imageTagCountCriterionHandler(qb *imageQueryBuilder, tagCount *models.IntCr
|
|||
|
||||
func imageGalleriesCriterionHandler(qb *imageQueryBuilder, galleries *models.MultiCriterionInput) criterionHandlerFunc {
|
||||
addJoinsFunc := func(f *filterBuilder) {
|
||||
qb.galleriesRepository().innerJoin(f, "galleries_join", "images.id")
|
||||
f.addInnerJoin(galleryTable, "", "galleries_join.gallery_id = galleries.id")
|
||||
qb.galleriesRepository().join(f, "galleries_join", "images.id")
|
||||
f.addLeftJoin(galleryTable, "", "galleries_join.gallery_id = galleries.id")
|
||||
}
|
||||
h := qb.getMultiCriterionHandlerBuilder(galleryTable, galleriesImagesTable, galleryIDColumn, addJoinsFunc)
|
||||
|
||||
|
|
|
@ -490,6 +490,8 @@ func TestImageQueryIsMissingGalleries(t *testing.T) {
|
|||
t.Errorf("Error querying image: %s", err.Error())
|
||||
}
|
||||
|
||||
assert.Greater(t, len(images), 0)
|
||||
|
||||
// ensure non of the ids equal the one with gallery
|
||||
for _, image := range images {
|
||||
assert.NotEqual(t, imageIDs[imageIdxWithGallery], image.ID)
|
||||
|
@ -641,11 +643,7 @@ func TestImageQueryGallery(t *testing.T) {
|
|||
Galleries: &galleryCriterion,
|
||||
}
|
||||
|
||||
images, _, err := queryImagesWithCount(sqb, &imageFilter, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Error querying image: %s", err.Error())
|
||||
}
|
||||
|
||||
images := queryImages(t, sqb, &imageFilter, nil)
|
||||
assert.Len(t, images, 1)
|
||||
|
||||
// ensure ids are correct
|
||||
|
@ -661,10 +659,7 @@ func TestImageQueryGallery(t *testing.T) {
|
|||
Modifier: models.CriterionModifierIncludesAll,
|
||||
}
|
||||
|
||||
images, _, err = queryImagesWithCount(sqb, &imageFilter, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Error querying image: %s", err.Error())
|
||||
}
|
||||
images = queryImages(t, sqb, &imageFilter, nil)
|
||||
|
||||
assert.Len(t, images, 1)
|
||||
assert.Equal(t, imageIDs[imageIdxWithTwoGalleries], images[0].ID)
|
||||
|
@ -681,12 +676,13 @@ func TestImageQueryGallery(t *testing.T) {
|
|||
Q: &q,
|
||||
}
|
||||
|
||||
images, _, err = queryImagesWithCount(sqb, &imageFilter, &findFilter)
|
||||
if err != nil {
|
||||
t.Errorf("Error querying image: %s", err.Error())
|
||||
}
|
||||
images = queryImages(t, sqb, &imageFilter, &findFilter)
|
||||
assert.Len(t, images, 0)
|
||||
|
||||
q = getImageStringValue(imageIdxWithPerformer, titleField)
|
||||
images = queryImages(t, sqb, &imageFilter, &findFilter)
|
||||
assert.Len(t, images, 1)
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
|
@ -297,6 +297,7 @@ func (r *repository) join(j joiner, as string, parentIDCol string) {
|
|||
j.addLeftJoin(r.tableName, as, fmt.Sprintf("%s.%s = %s", t, r.idColumn, parentIDCol))
|
||||
}
|
||||
|
||||
//nolint:golint,unused
|
||||
func (r *repository) innerJoin(j joiner, as string, parentIDCol string) {
|
||||
t := r.tableName
|
||||
if as != "" {
|
||||
|
|
Loading…
Reference in New Issue