diff --git a/src/backend/model/database/sql/PreviewManager.ts b/src/backend/model/database/sql/PreviewManager.ts index a3c44da8..e4ea0d0c 100644 --- a/src/backend/model/database/sql/PreviewManager.ts +++ b/src/backend/model/database/sql/PreviewManager.ts @@ -8,10 +8,11 @@ import {SortingMethods} from '../../../../common/entities/SortingMethods'; import {ISQLSearchManager} from './ISearchManager'; import {IPreviewManager, PreviewPhotoDTOWithID} from '../interfaces/IPreviewManager'; import {SQLConnection} from './SQLConnection'; -import {SearchQueryDTO} from '../../../../common/entities/SearchQueryDTO'; +import {SearchQueryDTO, SearchQueryTypes, TextSearch} from '../../../../common/entities/SearchQueryDTO'; import {DirectoryEntity} from './enitites/DirectoryEntity'; import {ParentDirectoryDTO} from '../../../../common/entities/DirectoryDTO'; import * as path from 'path'; +import {Utils} from '../../../../common/Utils'; const LOG_TAG = '[PreviewManager]'; @@ -108,7 +109,8 @@ export class PreviewManager implements IPreviewManager { }; let previewMedia = null; - if (Config.Server.Preview.SearchQuery) { + if (Config.Server.Preview.SearchQuery && + !Utils.equalsFilter(Config.Server.Preview.SearchQuery, {type: SearchQueryTypes.any_text, text: ''} as TextSearch)) { previewMedia = await (await previewQuery()) .andWhere(await (ObjectManagers.getInstance().SearchManager as ISQLSearchManager) .prepareAndBuildWhereQuery(Config.Server.Preview.SearchQuery)) @@ -169,7 +171,11 @@ export class PreviewManager implements IPreviewManager { let previewMedia: PreviewPhotoDTOWithID = null; - if (Config.Server.Preview.SearchQuery) { + if (Config.Server.Preview.SearchQuery && + !Utils.equalsFilter(Config.Server.Preview.SearchQuery, { + type: SearchQueryTypes.any_text, + text: '' + } as TextSearch)) { previewMedia = await previewQuery() .andWhere(await (ObjectManagers.getInstance().SearchManager as ISQLSearchManager) .prepareAndBuildWhereQuery(Config.Server.Preview.SearchQuery)) diff --git a/test/backend/unit/model/sql/GalleryManager.spec.ts b/test/backend/unit/model/sql/GalleryManager.spec.ts index bdb1fa09..06fd7ace 100644 --- a/test/backend/unit/model/sql/GalleryManager.spec.ts +++ b/test/backend/unit/model/sql/GalleryManager.spec.ts @@ -36,53 +36,4 @@ class GalleryManagerTest extends GalleryManager { describe('GalleryManager', (sqlHelper: DBTestHelper) => { describe = tmpDescribe; - - const setUpSqlDB = async () => { - await sqlHelper.initDB(); - await sqlHelper.setUpTestGallery(); - await ObjectManagers.InitSQLManagers(); - }; - - before(setUpSqlDB); - after(sqlHelper.clearDB); - - it('should invalidate and update preview', async () => { - const gm = new GalleryManagerTest(); - const conn = await SQLConnection.getConnection(); - - const selectDir = async () => { - return await conn.getRepository(DirectoryEntity).findOne({id: sqlHelper.testGalleyEntities.subDir.id}, { - join: { - alias: 'dir', - leftJoinAndSelect: {preview: 'dir.preview'} - } - }); - }; - - - let subdir = await selectDir(); - - expect(subdir.validPreview).to.equal(true); - expect(subdir.preview.id).to.equal(1); - - // new version should invalidate - await gm.onNewDataVersion(sqlHelper.testGalleyEntities.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(1); - - await conn.createQueryBuilder() - .update(DirectoryEntity) - .set({validPreview: false, preview: null}).execute(); - expect((await selectDir()).preview).to.equal(null); - - const res = await gm.selectParentDir(conn, sqlHelper.testGalleyEntities.dir.name, sqlHelper.testGalleyEntities.dir.path); - await gm.fillParentDir(conn, res); - subdir = await selectDir(); - expect(subdir.validPreview).to.equal(true); - expect(subdir.preview.id).to.equal(1); - - }); - }); diff --git a/test/backend/unit/model/sql/PreviewManager.spec.ts b/test/backend/unit/model/sql/PreviewManager.spec.ts index 68d479fd..4f252796 100644 --- a/test/backend/unit/model/sql/PreviewManager.spec.ts +++ b/test/backend/unit/model/sql/PreviewManager.spec.ts @@ -221,4 +221,45 @@ describe('PreviewManager', (sqlHelper: DBTestHelper) => { }); + + it('should invalidate and update preview', async () => { + const gm = new GalleryManagerTest(); + const pm = new PreviewManager(); + const conn = await SQLConnection.getConnection(); + + const selectDir = async () => { + return await conn.getRepository(DirectoryEntity).findOne({id: subDir.id}, { + join: { + alias: 'dir', + leftJoinAndSelect: {preview: 'dir.preview'} + } + }); + }; + + + let subdir = await selectDir(); + + expect(subdir.validPreview).to.equal(true); + expect(subdir.preview.id).to.equal(2); + + // 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); + + await conn.createQueryBuilder() + .update(DirectoryEntity) + .set({validPreview: false, preview: null}).execute(); + expect((await selectDir()).preview).to.equal(null); + + const res = await gm.selectParentDir(conn, dir.name, dir.path); + await gm.fillParentDir(conn, res); + subdir = await selectDir(); + expect(subdir.validPreview).to.equal(true); + expect(subdir.preview.id).to.equal(2); + + }); + });