diff --git a/pkg/sqlite/image.go b/pkg/sqlite/image.go index aa2125cd0..480b9a6b9 100644 --- a/pkg/sqlite/image.go +++ b/pkg/sqlite/image.go @@ -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) diff --git a/pkg/sqlite/image_test.go b/pkg/sqlite/image_test.go index c90fb4547..552db2cdf 100644 --- a/pkg/sqlite/image_test.go +++ b/pkg/sqlite/image_test.go @@ -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 }) } diff --git a/pkg/sqlite/repository.go b/pkg/sqlite/repository.go index ed0d4ac0d..49329f13c 100644 --- a/pkg/sqlite/repository.go +++ b/pkg/sqlite/repository.go @@ -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 != "" {