mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Gallery scrubber (#5133)
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user