From 8a10ce4798f561a6de2bad2a5a760ddc46a8b7b7 Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Wed, 1 Nov 2023 20:23:47 -0400 Subject: [PATCH] sql - fetch_catalog needs ORDER BY bump time after all those operations --- sql/archive_tests.sql | 8 +++++++- sql/archive_tests2.sql | 11 +++++++++-- sql/initialize.sql | 5 ++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/sql/archive_tests.sql b/sql/archive_tests.sql index 333ab69..4d09d1c 100644 --- a/sql/archive_tests.sql +++ b/sql/archive_tests.sql @@ -588,7 +588,13 @@ grouped AS ( $$; -SELECT * FROM posts WHERE body_search_index @@ websearch_to_tsquery('english', 'TRUE CHRISTIAN'); +SELECT * FROM posts WHERE body_search_index @@ websearch_to_tsquery('english', 'holocaust'); +SELECT *, + ts_rank(body_search_index, websearch_to_tsquery('english', 'holocaust')) AS relevance +FROM posts +WHERE body_search_index @@ websearch_to_tsquery('english', 'holocaust') +ORDER BY relevance DESC; + SELECT to_tsvector('english', body) FROM posts WHERE board_post_id = 476524; SELECT (setweight(to_tsvector('english', COALESCE(subject, '')), 'A') || setweight(to_tsvector('english', COALESCE(name, '')), 'B') || diff --git a/sql/archive_tests2.sql b/sql/archive_tests2.sql index be828ea..ca37dc0 100644 --- a/sql/archive_tests2.sql +++ b/sql/archive_tests2.sql @@ -140,7 +140,9 @@ RETURNS TABLE ( post_id bigint, board_post_id bigint, creation_time timestamptz, + bump_time timestamptz, body text, + subject text, thread_id bigint, board_thread_id bigint, pathpart text, @@ -158,7 +160,9 @@ RETURNS TABLE ( posts.post_id, posts.board_post_id, posts.creation_time, + top.bump_time, posts.body, + posts.subject, posts.thread_id FROM top JOIN posts ON top.thread_id = posts.thread_id @@ -187,12 +191,15 @@ RETURNS TABLE ( JOIN post_counts ON op_posts.thread_id = post_counts.thread_id JOIN threads ON op_posts.thread_id = threads.thread_id JOIN boards ON threads.board_id = boards.board_id - JOIN sites ON sites.site_id = boards.site_id; + JOIN sites ON sites.site_id = boards.site_id + ORDER BY bump_time DESC; $$ LANGUAGE sql; SELECT * FROM fetch_catalog(NOW() - INTERVAL '1y', 1001); -SELECT * FROM fetch_catalog(NOW(), 2000); +SELECT * FROM fetch_catalog(NOW(), 1000); + +SELECT count(*) FROM posts; -- CREATE INDEX idx_posts_thread_board ON posts (thread_id, board_post_id); ANALYZE posts; diff --git a/sql/initialize.sql b/sql/initialize.sql index 1f50ce0..aa1be8b 100644 --- a/sql/initialize.sql +++ b/sql/initialize.sql @@ -211,6 +211,7 @@ RETURNS TABLE ( post_id bigint, board_post_id bigint, creation_time timestamptz, + bump_time timestamptz, body text, subject text, thread_id bigint, @@ -230,6 +231,7 @@ RETURNS TABLE ( posts.post_id, posts.board_post_id, posts.creation_time, + top.bump_time, posts.body, posts.subject, posts.thread_id @@ -260,7 +262,8 @@ RETURNS TABLE ( JOIN post_counts ON op_posts.thread_id = post_counts.thread_id JOIN threads ON op_posts.thread_id = threads.thread_id JOIN boards ON threads.board_id = boards.board_id - JOIN sites ON sites.site_id = boards.site_id; + JOIN sites ON sites.site_id = boards.site_id + ORDER BY bump_time DESC; $$ LANGUAGE sql;