1
0
mirror of https://github.com/mastodon/mastodon synced 2024-12-01 08:18:22 +09:00
mastodon/db/views/instances_v01.sql
Eugen Rochko 216b85b053
Fix performance on instances list in admin UI (#15282)
- Reduce duplicate queries
- Remove n+1 queries
- Add accounts count to detailed view
- Add separate action log entry for updating existing domain blocks
2020-12-14 09:06:34 +01:00

18 lines
550 B
SQL

WITH domain_counts(domain, accounts_count)
AS (
SELECT domain, COUNT(*) as accounts_count
FROM accounts
WHERE domain IS NOT NULL
GROUP BY domain
)
SELECT domain, accounts_count
FROM domain_counts
UNION
SELECT domain_blocks.domain, COALESCE(domain_counts.accounts_count, 0)
FROM domain_blocks
LEFT OUTER JOIN domain_counts ON domain_counts.domain = domain_blocks.domain
UNION
SELECT domain_allows.domain, COALESCE(domain_counts.accounts_count, 0)
FROM domain_allows
LEFT OUTER JOIN domain_counts ON domain_counts.domain = domain_allows.domain