[backend] Improve postgres FTS mention filter query

This commit is contained in:
Laura Hausmann 2023-11-18 18:23:16 +01:00
parent 292e537dc7
commit b7a5c192d8
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -97,14 +97,16 @@ function fromFilterInverse(query: SelectQueryBuilder<any>, filter: string, id: n
function mentionFilter(query: SelectQueryBuilder<any>, filter: string, id: number) { function mentionFilter(query: SelectQueryBuilder<any>, filter: string, id: number) {
const userQuery = generateUserSubquery(filter, id); const userQuery = generateUserSubquery(filter, id);
query.andWhere(`note.mentions @> array[(${userQuery.getQuery()})]`); query.addCommonTableExpression(userQuery.getQuery(), `cte_${id}`, { materialized: true })
query.setParameters(userQuery.getParameters()); query.andWhere(`note.mentions @> array[(SELECT * FROM cte_${id})]::varchar[]`);
query.setParameters(userQuery.getParameters());
} }
function mentionFilterInverse(query: SelectQueryBuilder<any>, filter: string, id: number) { function mentionFilterInverse(query: SelectQueryBuilder<any>, filter: string, id: number) {
const userQuery = generateUserSubquery(filter, id); const userQuery = generateUserSubquery(filter, id);
query.andWhere(`NOT (note.mentions @> array[(${userQuery.getQuery()})])`); query.addCommonTableExpression(userQuery.getQuery(), `cte_${id}`, { materialized: true })
query.setParameters(userQuery.getParameters()); query.andWhere(`NOT (note.mentions @> array[(SELECT * FROM cte_${id})]::varchar[])`);
query.setParameters(userQuery.getParameters());
} }
function replyFilter(query: SelectQueryBuilder<any>, filter: string, id: number) { function replyFilter(query: SelectQueryBuilder<any>, filter: string, id: number) {