mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
fixing preview issue: typeorm's parametrized SQL query was overriding each other, lets make them unique.
This commit is contained in:
parent
a749ba3a58
commit
433d7724ce
@ -94,7 +94,8 @@ export class PreviewManager implements IPreviewManager {
|
||||
|
||||
public async getAlbumPreview(album: { searchQuery: SearchQueryDTO }): Promise<PreviewPhotoDTOWithID> {
|
||||
|
||||
const albumQuery: Brackets = 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 = (): SelectQueryBuilder<MediaEntity> => {
|
||||
@ -111,9 +112,10 @@ 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)) {
|
||||
const previewFilterQuery = await (ObjectManagers.getInstance().SearchManager as ISQLSearchManager)
|
||||
.prepareAndBuildWhereQuery(Config.Server.Preview.SearchQuery);
|
||||
previewMedia = await previewQuery()
|
||||
.andWhere(await (ObjectManagers.getInstance().SearchManager as ISQLSearchManager)
|
||||
.prepareAndBuildWhereQuery(Config.Server.Preview.SearchQuery))
|
||||
.andWhere(previewFilterQuery)
|
||||
.limit(1)
|
||||
.getOne();
|
||||
}
|
||||
|
@ -44,6 +44,8 @@ export class SearchManager implements ISQLSearchManager {
|
||||
'CONCAT(\'[\' , GROUP_CONCAT( \'{"name": "\' , person.name , \'", "box": {"top":\' , faces.box.top , \', "left":\' , faces.box.left , \', "height":\' , faces.box.height ,\', "width":\' , faces.box.width , \'}}\' ) ,\']\') as media_metadataFaces' :
|
||||
'\'[\' || GROUP_CONCAT( \'{"name": "\' || person.name || \'", "box": {"top":\' || faces.box.top || \', "left":\' || faces.box.left || \', "height":\' || faces.box.height ||\', "width":\' || faces.box.width || \'}}\' ) ||\']\' as media_metadataFaces';
|
||||
private DIRECTORY_SELECT = ['directory.id', 'directory.name', 'directory.path'];
|
||||
// makes all search query params unique, so typeorm wont mix them
|
||||
private queryIdBase = 0;
|
||||
|
||||
private static autoCompleteItemsUnique(array: Array<AutoCompleteItem>): Array<AutoCompleteItem> {
|
||||
const a = array.concat();
|
||||
@ -247,7 +249,6 @@ export class SearchManager implements ISQLSearchManager {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public async getCount(query: SearchQueryDTO): Promise<number> {
|
||||
const connection = await SQLConnection.getConnection();
|
||||
|
||||
@ -660,11 +661,21 @@ export class SearchManager implements ISQLSearchManager {
|
||||
* Witch SOME_OF query the number of WHERE constrains have O(N!) complexity
|
||||
*/
|
||||
private assignQueryIDs(queryIN: SearchQueryDTO, id = {value: 1}): SearchQueryDTO {
|
||||
|
||||
// It is possible that one SQL query contains multiple searchQueries
|
||||
// (like: where (<searchQuery1> AND (<searchQuery2>))
|
||||
// lets make params unique across multiple queries
|
||||
if (id.value === 1) {
|
||||
this.queryIdBase++;
|
||||
if (this.queryIdBase > 10000) {
|
||||
this.queryIdBase = 0;
|
||||
}
|
||||
}
|
||||
if ((queryIN as SearchListQuery).list) {
|
||||
(queryIN as SearchListQuery).list.forEach(q => this.assignQueryIDs(q, id));
|
||||
return queryIN;
|
||||
}
|
||||
(queryIN as SearchQueryDTOWithID).queryId = id.value;
|
||||
(queryIN as SearchQueryDTOWithID).queryId = this.queryIdBase + '_' + id.value;
|
||||
id.value++;
|
||||
return queryIN;
|
||||
}
|
||||
@ -732,5 +743,5 @@ export class SearchManager implements ISQLSearchManager {
|
||||
}
|
||||
|
||||
export interface SearchQueryDTOWithID extends SearchQueryDTO {
|
||||
queryId: number;
|
||||
queryId: string;
|
||||
}
|
||||
|
@ -231,6 +231,14 @@ describe('PreviewManager', (sqlHelper: DBTestHelper) => {
|
||||
text: 'Derem'
|
||||
} as TextSearch
|
||||
}))).to.deep.equalInAnyOrder(previewifyMedia(p2));
|
||||
// having a saved search that does not have any image
|
||||
Config.Server.Preview.SearchQuery = {type: SearchQueryTypes.any_text, text: 'Derem'} as TextSearch;
|
||||
expect(Utils.clone(await pm.getAlbumPreview({
|
||||
searchQuery: {
|
||||
type: SearchQueryTypes.any_text,
|
||||
text: 'wont find it'
|
||||
} as TextSearch
|
||||
}))).to.deep.equal(null);
|
||||
});
|
||||
|
||||
it('should invalidate and update preview', async () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user