Fix gallery scrubber image order (#5222)

This commit is contained in:
WithoutPants 2024-09-05 12:59:20 +10:00 committed by GitHub
parent 601a16b5cb
commit 8c2a25b833
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -602,6 +602,11 @@ func (qb *ImageStore) FindByChecksum(ctx context.Context, checksum string) ([]*m
}) })
} }
var defaultGalleryOrder = []exp.OrderedExpression{
goqu.L("COALESCE(folders.path, '') || COALESCE(files.basename, '') COLLATE NATURAL_CI").Asc(),
goqu.L("COALESCE(images.title, images.id) COLLATE NATURAL_CI").Asc(),
}
func (qb *ImageStore) FindByGalleryID(ctx context.Context, galleryID int) ([]*models.Image, error) { func (qb *ImageStore) FindByGalleryID(ctx context.Context, galleryID int) ([]*models.Image, error) {
table := qb.table() table := qb.table()
@ -618,7 +623,7 @@ func (qb *ImageStore) FindByGalleryID(ctx context.Context, galleryID int) ([]*mo
table.Col(idColumn).Eq( table.Col(idColumn).Eq(
sq, sq,
), ),
).Order(goqu.L("COALESCE(folders.path, '') || COALESCE(files.basename, '') COLLATE NATURAL_CI").Asc()) ).Order(defaultGalleryOrder...)
ret, err := qb.getMany(ctx, q) ret, err := qb.getMany(ctx, q)
if err != nil { if err != nil {
@ -630,8 +635,6 @@ func (qb *ImageStore) FindByGalleryID(ctx context.Context, galleryID int) ([]*mo
func (qb *ImageStore) FindByGalleryIDIndex(ctx context.Context, galleryID int, index uint) (*models.Image, error) { func (qb *ImageStore) FindByGalleryIDIndex(ctx context.Context, galleryID int, index uint) (*models.Image, error) {
table := qb.table() table := qb.table()
fileTable := fileTableMgr.table
folderTable := folderTableMgr.table
q := qb.selectDataset(). q := qb.selectDataset().
InnerJoin( InnerJoin(
@ -640,7 +643,7 @@ func (qb *ImageStore) FindByGalleryIDIndex(ctx context.Context, galleryID int, i
). ).
Where(galleriesImagesJoinTable.Col(galleryIDColumn).Eq(galleryID)). Where(galleriesImagesJoinTable.Col(galleryIDColumn).Eq(galleryID)).
Prepared(true). Prepared(true).
Order(folderTable.Col("path").Asc(), fileTable.Col("basename").Asc()). Order(defaultGalleryOrder...).
Limit(1).Offset(index) Limit(1).Offset(index)
ret, err := qb.getMany(ctx, q) ret, err := qb.getMany(ctx, q)