Optimize comment RSS sql query

This commit is contained in:
Chocobozzz 2020-08-20 08:52:16 +02:00
parent 1c5c31a1ce
commit 1c58423f6c
No known key found for this signature in database
GPG key ID: 583A612D890159BE
2 changed files with 40 additions and 14 deletions

View file

@ -129,6 +129,30 @@ function buildBlockedAccountSQL (blockerIds: number[]) {
'WHERE "serverBlocklist"."accountId" IN (' + blockerIdsString + ')'
}
function buildBlockedAccountSQLOptimized (columnNameJoin: string, blockerIds: number[]) {
const blockerIdsString = blockerIds.join(', ')
return [
literal(
`NOT EXISTS (` +
` SELECT 1 FROM "accountBlocklist" ` +
` WHERE "targetAccountId" = ${columnNameJoin} ` +
` AND "accountId" IN (${blockerIdsString})` +
`)`
),
literal(
`NOT EXISTS (` +
` SELECT 1 FROM "account" ` +
` INNER JOIN "actor" ON account."actorId" = actor.id ` +
` INNER JOIN "serverBlocklist" ON "actor"."serverId" = "serverBlocklist"."targetServerId" ` +
` WHERE "account"."id" = ${columnNameJoin} ` +
` AND "serverBlocklist"."accountId" IN (${blockerIdsString})` +
`)`
)
]
}
function buildServerIdsFollowedBy (actorId: any) {
const actorIdNumber = parseInt(actorId + '', 10)
@ -201,6 +225,7 @@ function searchAttribute (sourceField?: string, targetField?: string) {
export {
buildBlockedAccountSQL,
buildBlockedAccountSQLOptimized,
buildLocalActorIdsIn,
SortType,
buildLocalAccountIdsIn,