| 1 | -- Additive indexes for the public forum read and anti-abuse paths. |
| 2 | -- Apply before deploying the matching Worker: |
| 3 | -- wrangler d1 execute reasonix-forum --remote --file=migrate-performance-indexes.sql |
| 4 | |
| 5 | CREATE INDEX IF NOT EXISTS posts_author_created_at |
| 6 | ON posts (author, created_at); |
| 7 | |
| 8 | CREATE INDEX IF NOT EXISTS posts_visible_topic |
| 9 | ON posts (topic_id, created_at) |
| 10 | WHERE status = 'visible'; |
| 11 | |
| 12 | CREATE INDEX IF NOT EXISTS topics_visible_latest |
| 13 | ON topics (pinned DESC, last_post_at DESC) |
| 14 | WHERE status <> 'hidden'; |
| 15 | |
| 16 | CREATE INDEX IF NOT EXISTS topics_visible_top |
| 17 | ON topics (reply_count DESC, last_post_at DESC) |
| 18 | WHERE status <> 'hidden'; |
| 19 |