perf(feed): replace correlated subqueries with LEFT JOIN aggregations
Feed queries ran 5 correlated subqueries per row (3 COUNT + 2 EXISTS for engagement counts and viewer context). Replaced with LEFT JOIN aggregations computed once per query. Adds migration 016 with indexes on likes(thought_id), boosts(thought_id), thoughts(in_reply_to_id), and compound viewer-context indexes — expected to drop ~3s queries to <100ms on typical page sizes. Also removes WebFinger from the footer (requires query params, zero standalone value as a link).
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
-- Indexes for feed engagement counts and sorting.
|
||||
-- likes and boosts are joined/counted per thought on every feed query.
|
||||
-- thoughts(in_reply_to_id) is scanned for reply_count.
|
||||
CREATE INDEX IF NOT EXISTS idx_likes_thought_id ON likes(thought_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_boosts_thought_id ON boosts(thought_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_thoughts_in_reply_to_id ON thoughts(in_reply_to_id) WHERE in_reply_to_id IS NOT NULL;
|
||||
|
||||
-- Viewer-context lookups: "did I like/boost this?"
|
||||
CREATE INDEX IF NOT EXISTS idx_likes_user_thought ON likes(user_id, thought_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_boosts_user_thought ON boosts(user_id, thought_id);
|
||||
Reference in New Issue
Block a user