diff options
Diffstat (limited to 'server/models/utils.ts')
-rw-r--r-- | server/models/utils.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/server/models/utils.ts b/server/models/utils.ts index d706d9ea8..6e5522346 100644 --- a/server/models/utils.ts +++ b/server/models/utils.ts | |||
@@ -129,6 +129,30 @@ function buildBlockedAccountSQL (blockerIds: number[]) { | |||
129 | 'WHERE "serverBlocklist"."accountId" IN (' + blockerIdsString + ')' | 129 | 'WHERE "serverBlocklist"."accountId" IN (' + blockerIdsString + ')' |
130 | } | 130 | } |
131 | 131 | ||
132 | function buildBlockedAccountSQLOptimized (columnNameJoin: string, blockerIds: number[]) { | ||
133 | const blockerIdsString = blockerIds.join(', ') | ||
134 | |||
135 | return [ | ||
136 | literal( | ||
137 | `NOT EXISTS (` + | ||
138 | ` SELECT 1 FROM "accountBlocklist" ` + | ||
139 | ` WHERE "targetAccountId" = ${columnNameJoin} ` + | ||
140 | ` AND "accountId" IN (${blockerIdsString})` + | ||
141 | `)` | ||
142 | ), | ||
143 | |||
144 | literal( | ||
145 | `NOT EXISTS (` + | ||
146 | ` SELECT 1 FROM "account" ` + | ||
147 | ` INNER JOIN "actor" ON account."actorId" = actor.id ` + | ||
148 | ` INNER JOIN "serverBlocklist" ON "actor"."serverId" = "serverBlocklist"."targetServerId" ` + | ||
149 | ` WHERE "account"."id" = ${columnNameJoin} ` + | ||
150 | ` AND "serverBlocklist"."accountId" IN (${blockerIdsString})` + | ||
151 | `)` | ||
152 | ) | ||
153 | ] | ||
154 | } | ||
155 | |||
132 | function buildServerIdsFollowedBy (actorId: any) { | 156 | function buildServerIdsFollowedBy (actorId: any) { |
133 | const actorIdNumber = parseInt(actorId + '', 10) | 157 | const actorIdNumber = parseInt(actorId + '', 10) |
134 | 158 | ||
@@ -201,6 +225,7 @@ function searchAttribute (sourceField?: string, targetField?: string) { | |||
201 | 225 | ||
202 | export { | 226 | export { |
203 | buildBlockedAccountSQL, | 227 | buildBlockedAccountSQL, |
228 | buildBlockedAccountSQLOptimized, | ||
204 | buildLocalActorIdsIn, | 229 | buildLocalActorIdsIn, |
205 | SortType, | 230 | SortType, |
206 | buildLocalAccountIdsIn, | 231 | buildLocalAccountIdsIn, |