[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 'image':
case 'video': case 'video':
case 'audio': 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; break;
case 'file': case 'file':
query.andWhere(`note.attachedFileTypes <> '{}'`); query.andWhere(`note."attachedFileTypes" <> '{}'`);
query.andWhere(`NOT (note.attachedFileTypes && array[:...types]::varchar[])`, { types: FILE_TYPE_BROWSERSAFE }); 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; break;
default: default:
break; break;