[backend] Improve postgres FTS attachment filter query

This commit is contained in:
Laura Hausmann 2023-11-18 17:50:27 +01:00
parent 1b4fedc59f
commit 292e537dc7
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605

View File

@ -178,11 +178,13 @@ function attachmentFilter(query: SelectQueryBuilder<any>, filter: string) {
case 'image':
case 'video':
case 'audio':
query.andWhere(`note.attachedFileTypes && array[:...types]::varchar[]`, { types: FILE_TYPE_BROWSERSAFE.filter(t => t.startsWith(`${filter}/`)) });
query.andWhere(`note."attachedFileTypes"::varchar ILIKE :type`, { type: `%${sqlLikeEscape(filter)}/%` });
break;
case 'file':
query.andWhere(`note.attachedFileTypes <> '{}'`);
query.andWhere(`NOT (note.attachedFileTypes && array[:...types]::varchar[])`, { types: FILE_TYPE_BROWSERSAFE });
query.andWhere(`note."attachedFileTypes" <> '{}'`);
query.andWhere(`NOT (note."attachedFileTypes"::varchar ILIKE '%image/%')`);
query.andWhere(`NOT (note."attachedFileTypes"::varchar ILIKE '%video/%')`);
query.andWhere(`NOT (note."attachedFileTypes"::varchar ILIKE '%audio/%')`);
break;
default:
break;