mirror of
https://github.com/bpatrik/pigallery2.git
synced 2024-12-02 09:12:07 +02:00
fixing preview manager ordering
This commit is contained in:
parent
0cd5e90866
commit
6c6d77ad34
@ -36,7 +36,7 @@ export class PreviewManager implements IPreviewManager {
|
||||
query.addOrderBy('media.rating', 'ASC');
|
||||
break;
|
||||
case SortingMethods.descName:
|
||||
query.addOrderBy('media.name', 'ASC');
|
||||
query.addOrderBy('media.name', 'DESC');
|
||||
break;
|
||||
case SortingMethods.ascName:
|
||||
query.addOrderBy('media.name', 'ASC');
|
||||
@ -94,10 +94,10 @@ export class PreviewManager implements IPreviewManager {
|
||||
|
||||
public async getAlbumPreview(album: { searchQuery: SearchQueryDTO }): Promise<PreviewPhotoDTOWithID> {
|
||||
|
||||
const albumQuery = await (ObjectManagers.getInstance().SearchManager as ISQLSearchManager).prepareAndBuildWhereQuery(album.searchQuery);
|
||||
const albumQuery: Brackets = await (ObjectManagers.getInstance().SearchManager as ISQLSearchManager).prepareAndBuildWhereQuery(album.searchQuery);
|
||||
const connection = await SQLConnection.getConnection();
|
||||
|
||||
const previewQuery = async (): Promise<SelectQueryBuilder<MediaEntity>> => {
|
||||
const previewQuery = (): SelectQueryBuilder<MediaEntity> => {
|
||||
const query = connection
|
||||
.getRepository(MediaEntity)
|
||||
.createQueryBuilder('media')
|
||||
@ -111,7 +111,7 @@ export class PreviewManager implements IPreviewManager {
|
||||
let previewMedia = null;
|
||||
if (Config.Server.Preview.SearchQuery &&
|
||||
!Utils.equalsFilter(Config.Server.Preview.SearchQuery, {type: SearchQueryTypes.any_text, text: ''} as TextSearch)) {
|
||||
previewMedia = await (await previewQuery())
|
||||
previewMedia = await previewQuery()
|
||||
.andWhere(await (ObjectManagers.getInstance().SearchManager as ISQLSearchManager)
|
||||
.prepareAndBuildWhereQuery(Config.Server.Preview.SearchQuery))
|
||||
.limit(1)
|
||||
@ -119,7 +119,7 @@ export class PreviewManager implements IPreviewManager {
|
||||
}
|
||||
|
||||
if (!previewMedia) {
|
||||
previewMedia = await (await previewQuery())
|
||||
previewMedia = await previewQuery()
|
||||
.limit(1)
|
||||
.getOne();
|
||||
}
|
||||
|
@ -154,6 +154,9 @@ describe('PreviewManager', (sqlHelper: DBTestHelper) => {
|
||||
|
||||
after(async () => {
|
||||
await sqlHelper.clearDB();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
Config.Server.Preview.SearchQuery = null;
|
||||
Config.Server.Preview.Sorting = [SortingMethods.descRating, SortingMethods.descDate];
|
||||
});
|
||||
@ -218,10 +221,16 @@ describe('PreviewManager', (sqlHelper: DBTestHelper) => {
|
||||
text: 'sw'
|
||||
} as TextSearch
|
||||
}))).to.deep.equalInAnyOrder(previewifyMedia(p2));
|
||||
|
||||
// Having a preview search query that does not return valid result
|
||||
Config.Server.Preview.SearchQuery = {type: SearchQueryTypes.any_text, text: 'wont find it'} as TextSearch;
|
||||
expect(Utils.clone(await pm.getAlbumPreview({
|
||||
searchQuery: {
|
||||
type: SearchQueryTypes.any_text,
|
||||
text: 'Derem'
|
||||
} as TextSearch
|
||||
}))).to.deep.equalInAnyOrder(previewifyMedia(p2));
|
||||
});
|
||||
|
||||
|
||||
it('should invalidate and update preview', async () => {
|
||||
const gm = new GalleryManagerTest();
|
||||
const pm = new PreviewManager();
|
||||
@ -240,14 +249,14 @@ describe('PreviewManager', (sqlHelper: DBTestHelper) => {
|
||||
let subdir = await selectDir();
|
||||
|
||||
expect(subdir.validPreview).to.equal(true);
|
||||
expect(subdir.preview.id).to.equal(2);
|
||||
expect(subdir.preview.id).to.equal(p2.id);
|
||||
|
||||
// new version should invalidate
|
||||
await pm.onNewDataVersion(subDir as ParentDirectoryDTO);
|
||||
subdir = await selectDir();
|
||||
expect(subdir.validPreview).to.equal(false);
|
||||
// during invalidation, we do not remove the previous preview (it's good to show at least some photo)
|
||||
expect(subdir.preview.id).to.equal(2);
|
||||
expect(subdir.preview.id).to.equal(p2.id);
|
||||
|
||||
await conn.createQueryBuilder()
|
||||
.update(DirectoryEntity)
|
||||
@ -258,7 +267,7 @@ describe('PreviewManager', (sqlHelper: DBTestHelper) => {
|
||||
await gm.fillParentDir(conn, res);
|
||||
subdir = await selectDir();
|
||||
expect(subdir.validPreview).to.equal(true);
|
||||
expect(subdir.preview.id).to.equal(2);
|
||||
expect(subdir.preview.id).to.equal(p2.id);
|
||||
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user