Gallery scrubber (#5133)

This commit is contained in:
WithoutPants
2024-08-28 08:59:41 +10:00
committed by GitHub
parent ce47efc415
commit 996dfb1c2f
21 changed files with 501 additions and 102 deletions

View File

@@ -301,6 +301,29 @@ func (_m *ImageReaderWriter) FindByGalleryID(ctx context.Context, galleryID int)
return r0, r1
}
// FindByGalleryIDIndex provides a mock function with given fields: ctx, galleryID, index
func (_m *ImageReaderWriter) FindByGalleryIDIndex(ctx context.Context, galleryID int, index uint) (*models.Image, error) {
ret := _m.Called(ctx, galleryID, index)
var r0 *models.Image
if rf, ok := ret.Get(0).(func(context.Context, int, uint) *models.Image); ok {
r0 = rf(ctx, galleryID, index)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*models.Image)
}
}
var r1 error
if rf, ok := ret.Get(1).(func(context.Context, int, uint) error); ok {
r1 = rf(ctx, galleryID, index)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// FindByZipFileID provides a mock function with given fields: ctx, zipFileID
func (_m *ImageReaderWriter) FindByZipFileID(ctx context.Context, zipFileID models.FileID) ([]*models.Image, error) {
ret := _m.Called(ctx, zipFileID)

View File

@@ -18,6 +18,7 @@ type ImageFinder interface {
FindByFolderID(ctx context.Context, fileID FolderID) ([]*Image, error)
FindByZipFileID(ctx context.Context, zipFileID FileID) ([]*Image, error)
FindByGalleryID(ctx context.Context, galleryID int) ([]*Image, error)
FindByGalleryIDIndex(ctx context.Context, galleryID int, index uint) (*Image, error)
}
// ImageQueryer provides methods to query images.

View File

@@ -568,8 +568,6 @@ func (qb *ImageStore) FindByChecksum(ctx context.Context, checksum string) ([]*m
func (qb *ImageStore) FindByGalleryID(ctx context.Context, galleryID int) ([]*models.Image, error) {
table := qb.table()
fileTable := fileTableMgr.table
folderTable := folderTableMgr.table
sq := dialect.From(table).
InnerJoin(
@@ -584,7 +582,7 @@ func (qb *ImageStore) FindByGalleryID(ctx context.Context, galleryID int) ([]*mo
table.Col(idColumn).Eq(
sq,
),
).Order(folderTable.Col("path").Asc(), fileTable.Col("basename").Asc())
).Order(goqu.L("COALESCE(folders.path, '') || COALESCE(files.basename, '') COLLATE NATURAL_CI").Asc())
ret, err := qb.getMany(ctx, q)
if err != nil {
@@ -594,6 +592,33 @@ func (qb *ImageStore) FindByGalleryID(ctx context.Context, galleryID int) ([]*mo
return ret, nil
}
func (qb *ImageStore) FindByGalleryIDIndex(ctx context.Context, galleryID int, index uint) (*models.Image, error) {
table := qb.table()
fileTable := fileTableMgr.table
folderTable := folderTableMgr.table
q := qb.selectDataset().
InnerJoin(
galleriesImagesJoinTable,
goqu.On(table.Col(idColumn).Eq(galleriesImagesJoinTable.Col(imageIDColumn))),
).
Where(galleriesImagesJoinTable.Col(galleryIDColumn).Eq(galleryID)).
Prepared(true).
Order(folderTable.Col("path").Asc(), fileTable.Col("basename").Asc()).
Limit(1).Offset(index)
ret, err := qb.getMany(ctx, q)
if err != nil {
return nil, fmt.Errorf("getting images for gallery %d: %w", galleryID, err)
}
if len(ret) == 0 {
return nil, nil
}
return ret[0], nil
}
func (qb *ImageStore) CountByGalleryID(ctx context.Context, galleryID int) (int, error) {
joinTable := goqu.T(galleriesImagesTable)