Skip to content

Commit

Permalink
fix: NOT blockedHosts list query
Browse files Browse the repository at this point in the history
  • Loading branch information
nexryai committed Aug 20, 2024
1 parent 9821687 commit 75dece4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default define(meta, paramDef, async (ps, me) => {
if (ps.blocked) {
query.andWhere(meta.blockedHosts.length === 0 ? "1=0" : "instance.host ILIKE ANY(ARRAY[:...blocked])", { blocked: meta.blockedHosts.flatMap(x => [x, `%.${x}`]) });
} else {
query.andWhere(meta.blockedHosts.length === 0 ? "1=1" : "instance.host NOT ILIKE ANY(ARRAY[:...blocked])", { blocked: meta.blockedHosts.flatMap(x => [x, `%.${x}`]) });
query.andWhere(meta.blockedHosts.length === 0 ? "1=1" : "instance.host NOT ILIKE ALL(ARRAY[:...blocked])", { blocked: meta.blockedHosts.flatMap(x => [x, `%.${x}`]) });
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/backend/src/services/chart/charts/federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ export default class FederationChart extends Chart<typeof schema> {
Followings.createQueryBuilder("following")
.select("COUNT(DISTINCT following.followeeHost)")
.where("following.followeeHost IS NOT NULL")
.andWhere(meta.blockedHosts.length === 0 ? "1=1" : "following.followeeHost NOT ILIKE ANY(ARRAY[:...blocked]", { blocked: meta.blockedHosts.flatMap(x => [x, `%.${x}`]) })
.andWhere(meta.blockedHosts.length === 0 ? "1=1" : "following.followeeHost NOT ILIKE ALL(ARRAY[:...blocked]", { blocked: meta.blockedHosts.flatMap(x => [x, `%.${x}`]) })
.andWhere(`following.followeeHost NOT IN (${ suspendedInstancesQuery.getQuery() })`)
.getRawOne()
.then(x => parseInt(x.count, 10)),
Followings.createQueryBuilder("following")
.select("COUNT(DISTINCT following.followerHost)")
.where("following.followerHost IS NOT NULL")
.andWhere(meta.blockedHosts.length === 0 ? "1=1" : "following.followerHost NOT ILIKE ANY(ARRAY[:...blocked]", { blocked: meta.blockedHosts.flatMap(x => [x, `%.${x}`]) })
.andWhere(meta.blockedHosts.length === 0 ? "1=1" : "following.followerHost NOT ILIKE ALL(ARRAY[:...blocked]", { blocked: meta.blockedHosts.flatMap(x => [x, `%.${x}`]) })
.andWhere(`following.followerHost NOT IN (${ suspendedInstancesQuery.getQuery() })`)
.getRawOne()
.then(x => parseInt(x.count, 10)),
Followings.createQueryBuilder("following")
.select("COUNT(DISTINCT following.followeeHost)")
.where("following.followeeHost IS NOT NULL")
.andWhere(meta.blockedHosts.length === 0 ? "1=1" : "following.followeeHost NOT ILIKE ANY(ARRAY[:...blocked]", { blocked: meta.blockedHosts.flatMap(x => [x, `%.${x}`]) })
.andWhere(meta.blockedHosts.length === 0 ? "1=1" : "following.followeeHost NOT ILIKE ALL(ARRAY[:...blocked]", { blocked: meta.blockedHosts.flatMap(x => [x, `%.${x}`]) })
.andWhere(`following.followeeHost NOT IN (${ suspendedInstancesQuery.getQuery() })`)
.andWhere(`following.followeeHost IN (${ pubsubSubQuery.getQuery() })`)
.setParameters(pubsubSubQuery.getParameters())
Expand All @@ -63,15 +63,15 @@ export default class FederationChart extends Chart<typeof schema> {
Instances.createQueryBuilder("instance")
.select("COUNT(instance.id)")
.where(`instance.host IN (${ subInstancesQuery.getQuery() })`)
.andWhere(meta.blockedHosts.length === 0 ? "1=1" : "instance.host NOT ILIKE ANY(ARRAY[:...blocked]", { blocked: meta.blockedHosts.flatMap(x => [x, `%.${x}`]) })
.andWhere(meta.blockedHosts.length === 0 ? "1=1" : "instance.host NOT ILIKE ALL(ARRAY[:...blocked]", { blocked: meta.blockedHosts.flatMap(x => [x, `%.${x}`]) })
.andWhere("instance.isSuspended = false")
.andWhere("instance.lastCommunicatedAt > :gt", { gt: new Date(Date.now() - (1000 * 60 * 60 * 24 * 30)) })
.getRawOne()
.then(x => parseInt(x.count, 10)),
Instances.createQueryBuilder("instance")
.select("COUNT(instance.id)")
.where(`instance.host IN (${ pubInstancesQuery.getQuery() })`)
.andWhere(meta.blockedHosts.length === 0 ? "1=1" : "instance.host NOT ILIKE ANY(ARRAY[:...blocked]", { blocked: meta.blockedHosts.flatMap(x => [x, `%.${x}`]) })
.andWhere(meta.blockedHosts.length === 0 ? "1=1" : "instance.host NOT ILIKE ALL(ARRAY[:...blocked]", { blocked: meta.blockedHosts.flatMap(x => [x, `%.${x}`]) })
.andWhere("instance.isSuspended = false")
.andWhere("instance.lastCommunicatedAt > :gt", { gt: new Date(Date.now() - (1000 * 60 * 60 * 24 * 30)) })
.getRawOne()
Expand Down

0 comments on commit 75dece4

Please sign in to comment.