lemmy/migrations/2025-08-01-000041_remove-aggregate-tables/up.sql

482 lines
15 KiB
MySQL
Raw Permalink Normal View History

Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
-- Merge comment_aggregates into comment table
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
ALTER TABLE comment
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
ADD COLUMN score int NOT NULL DEFAULT 0,
ADD COLUMN upvotes int NOT NULL DEFAULT 0,
ADD COLUMN downvotes int NOT NULL DEFAULT 0,
ADD COLUMN child_count int NOT NULL DEFAULT 0,
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
ADD COLUMN hot_rank double precision NOT NULL DEFAULT 0.0001,
ADD COLUMN controversy_rank double precision NOT NULL DEFAULT 0,
ADD COLUMN report_count smallint NOT NULL DEFAULT 0,
ADD COLUMN unresolved_report_count smallint NOT NULL DEFAULT 0;
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
-- Disable the triggers temporarily
ALTER TABLE comment DISABLE TRIGGER ALL;
-- disable all table indexes
UPDATE
pg_index
SET
indisready = FALSE
WHERE
indrelid = (
SELECT
oid
FROM
pg_class
WHERE
relname = 'comment');
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
UPDATE
comment
SET
score = ca.score,
upvotes = ca.upvotes,
downvotes = ca.downvotes,
child_count = ca.child_count,
hot_rank = ca.hot_rank,
controversy_rank = ca.controversy_rank,
report_count = ca.report_count,
unresolved_report_count = ca.unresolved_report_count
FROM
comment_aggregates AS ca
WHERE
comment.id = ca.comment_id;
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
DROP TABLE comment_aggregates;
-- Re-enable triggers after upserts
ALTER TABLE comment ENABLE TRIGGER ALL;
-- Re-enable indexes
UPDATE
pg_index
SET
indisready = TRUE
WHERE
indrelid = (
SELECT
oid
FROM
pg_class
WHERE
relname = 'comment');
-- reindex
REINDEX TABLE comment;
-- 30s-2m each
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
CREATE INDEX idx_comment_controversy ON comment USING btree (controversy_rank DESC);
CREATE INDEX idx_comment_hot ON comment USING btree (hot_rank DESC, score DESC);
CREATE INDEX idx_comment_nonzero_hotrank ON comment USING btree (published)
WHERE (hot_rank <> (0)::double precision);
--CREATE INDEX idx_comment_published on comment USING btree (published DESC);
CREATE INDEX idx_comment_score ON comment USING btree (score DESC);
-- merge post_aggregates into post table
ALTER TABLE post
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
ADD COLUMN comments int NOT NULL DEFAULT 0,
ADD COLUMN score int NOT NULL DEFAULT 0,
ADD COLUMN upvotes int NOT NULL DEFAULT 0,
ADD COLUMN downvotes int NOT NULL DEFAULT 0,
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
ADD COLUMN newest_comment_time_necro timestamp with time zone NOT NULL DEFAULT now(),
ADD COLUMN newest_comment_time timestamp with time zone NOT NULL DEFAULT now(),
ADD COLUMN hot_rank double precision NOT NULL DEFAULT 0.0001,
ADD COLUMN hot_rank_active double precision NOT NULL DEFAULT 0.0001,
ADD COLUMN controversy_rank double precision NOT NULL DEFAULT 0,
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
ADD COLUMN instance_id int REFERENCES instance (id) ON UPDATE CASCADE ON DELETE CASCADE,
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
ADD COLUMN scaled_rank double precision NOT NULL DEFAULT 0.0001,
ADD COLUMN report_count smallint NOT NULL DEFAULT 0,
ADD COLUMN unresolved_report_count smallint NOT NULL DEFAULT 0;
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
-- Disable the triggers temporarily
ALTER TABLE post DISABLE TRIGGER ALL;
-- disable all table indexes
UPDATE
pg_index
SET
indisready = FALSE
WHERE
indrelid = (
SELECT
oid
FROM
pg_class
WHERE
relname = 'post');
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
UPDATE
post
SET
comments = pa.comments,
score = pa.score,
upvotes = pa.upvotes,
downvotes = pa.downvotes,
newest_comment_time_necro = pa.newest_comment_time_necro,
newest_comment_time = pa.newest_comment_time,
hot_rank = pa.hot_rank,
hot_rank_active = pa.hot_rank_active,
controversy_rank = pa.controversy_rank,
instance_id = pa.instance_id,
scaled_rank = pa.scaled_rank,
report_count = pa.report_count,
unresolved_report_count = pa.unresolved_report_count
FROM
post_aggregates AS pa
WHERE
post.id = pa.post_id;
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
-- Delete that data
DROP TABLE post_aggregates;
-- Re-enable triggers after upserts
ALTER TABLE post ENABLE TRIGGER ALL;
-- Re-enable indexes
UPDATE
pg_index
SET
indisready = TRUE
WHERE
indrelid = (
SELECT
oid
FROM
pg_class
WHERE
relname = 'post');
-- reindex
REINDEX TABLE post;
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_community_active ON post USING btree (community_id, featured_local DESC, hot_rank_active DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_community_controversy ON post USING btree (community_id, featured_local DESC, controversy_rank DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_community_hot ON post USING btree (community_id, featured_local DESC, hot_rank DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_community_most_comments ON post USING btree (community_id, featured_local DESC, comments DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_community_newest_comment_time ON post USING btree (community_id, featured_local DESC, newest_comment_time DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_community_newest_comment_time_necro ON post USING btree (community_id, featured_local DESC, newest_comment_time_necro DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
-- INDEX idx_post_community_published ON post USING btree (community_id, featured_local DESC, published DESC);
--CREATE INDEX idx_post_community_published_asc ON post USING btree (community_id, featured_local DESC, reverse_timestamp_sort (published) DESC);
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_community_scaled ON post USING btree (community_id, featured_local DESC, scaled_rank DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_community_score ON post USING btree (community_id, featured_local DESC, score DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_community_active ON post USING btree (community_id, featured_community DESC, hot_rank_active DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_community_controversy ON post USING btree (community_id, featured_community DESC, controversy_rank DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_community_hot ON post USING btree (community_id, featured_community DESC, hot_rank DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_community_most_comments ON post USING btree (community_id, featured_community DESC, comments DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_community_newest_comment_time ON post USING btree (community_id, featured_community DESC, newest_comment_time DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_community_newest_comment_time_necr ON post USING btree (community_id, featured_community DESC, newest_comment_time_necro DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
--CREATE INDEX idx_post_featured_community_published ON post USING btree (community_id, featured_community DESC, published DESC);
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_community_published_asc ON post USING btree (community_id, featured_community DESC, reverse_timestamp_sort (published) DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_community_scaled ON post USING btree (community_id, featured_community DESC, scaled_rank DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_community_score ON post USING btree (community_id, featured_community DESC, score DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_local_active ON post USING btree (featured_local DESC, hot_rank_active DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_local_controversy ON post USING btree (featured_local DESC, controversy_rank DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_local_hot ON post USING btree (featured_local DESC, hot_rank DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_local_most_comments ON post USING btree (featured_local DESC, comments DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_local_newest_comment_time ON post USING btree (featured_local DESC, newest_comment_time DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_local_newest_comment_time_necro ON post USING btree (featured_local DESC, newest_comment_time_necro DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_local_published ON post USING btree (featured_local DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_local_published_asc ON post USING btree (featured_local DESC, reverse_timestamp_sort (published) DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_local_scaled ON post USING btree (featured_local DESC, scaled_rank DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
2025-03-10 14:33:21 +00:00
CREATE INDEX idx_post_featured_local_score ON post USING btree (featured_local DESC, score DESC, published DESC, id DESC);
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
CREATE INDEX idx_post_nonzero_hotrank ON post USING btree (published DESC)
WHERE ((hot_rank <> (0)::double precision) OR (hot_rank_active <> (0)::double precision));
CREATE INDEX idx_post_published_asc ON post USING btree (reverse_timestamp_sort (published) DESC);
-- merge community_aggregates into community table
ALTER TABLE community
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
ADD COLUMN subscribers int NOT NULL DEFAULT 0,
ADD COLUMN posts int NOT NULL DEFAULT 0,
ADD COLUMN comments int NOT NULL DEFAULT 0,
ADD COLUMN users_active_day int NOT NULL DEFAULT 0,
ADD COLUMN users_active_week int NOT NULL DEFAULT 0,
ADD COLUMN users_active_month int NOT NULL DEFAULT 0,
ADD COLUMN users_active_half_year int NOT NULL DEFAULT 0,
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
ADD COLUMN hot_rank double precision NOT NULL DEFAULT 0.0001,
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
ADD COLUMN subscribers_local int NOT NULL DEFAULT 0,
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
ADD COLUMN report_count smallint NOT NULL DEFAULT 0,
ADD COLUMN unresolved_report_count smallint NOT NULL DEFAULT 0,
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
ADD COLUMN interactions_month int NOT NULL DEFAULT 0;
-- Disable the triggers temporarily
ALTER TABLE community DISABLE TRIGGER ALL;
-- disable all table indexes
UPDATE
pg_index
SET
indisready = FALSE
WHERE
indrelid = (
SELECT
oid
FROM
pg_class
WHERE
relname = 'community');
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
UPDATE
community
SET
subscribers = ca.subscribers,
posts = ca.posts,
comments = ca.comments,
users_active_day = ca.users_active_day,
users_active_week = ca.users_active_week,
users_active_month = ca.users_active_month,
users_active_half_year = ca.users_active_half_year,
hot_rank = ca.hot_rank,
subscribers_local = ca.subscribers_local,
report_count = ca.report_count,
unresolved_report_count = ca.unresolved_report_count,
interactions_month = ca.interactions_month
FROM
community_aggregates AS ca
WHERE
community.id = ca.community_id;
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
DROP TABLE community_aggregates;
-- Re-enable triggers after upserts
ALTER TABLE community ENABLE TRIGGER ALL;
-- Re-enable indexes
UPDATE
pg_index
SET
indisready = TRUE
WHERE
indrelid = (
SELECT
oid
FROM
pg_class
WHERE
relname = 'community');
-- reindex
REINDEX TABLE community;
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
CREATE INDEX idx_community_hot ON public.community USING btree (hot_rank DESC);
CREATE INDEX idx_community_nonzero_hotrank ON public.community USING btree (published)
WHERE (hot_rank <> (0)::double precision);
CREATE INDEX idx_community_subscribers ON public.community USING btree (subscribers DESC);
CREATE INDEX idx_community_users_active_month ON public.community USING btree (users_active_month DESC);
-- merge person_aggregates into person table
ALTER TABLE person
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
ADD COLUMN post_count int NOT NULL DEFAULT 0,
ADD COLUMN post_score int NOT NULL DEFAULT 0,
ADD COLUMN comment_count int NOT NULL DEFAULT 0,
ADD COLUMN comment_score int NOT NULL DEFAULT 0;
-- Disable the triggers temporarily
ALTER TABLE person DISABLE TRIGGER ALL;
-- disable all table indexes
UPDATE
pg_index
SET
indisready = FALSE
WHERE
indrelid = (
SELECT
oid
FROM
pg_class
WHERE
relname = 'person');
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
UPDATE
person
SET
post_count = pa.post_count,
post_score = pa.post_score,
comment_count = pa.comment_count,
comment_score = pa.comment_score
FROM
person_aggregates AS pa
WHERE
person.id = pa.person_id;
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
DROP TABLE person_aggregates;
-- Re-enable triggers after upserts
ALTER TABLE person ENABLE TRIGGER ALL;
-- Re-enable indexes
UPDATE
pg_index
SET
indisready = TRUE
WHERE
indrelid = (
SELECT
oid
FROM
pg_class
WHERE
relname = 'person');
-- reindex
REINDEX TABLE person;
-- merge site_aggregates into local_site table
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
ALTER TABLE local_site
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
ADD COLUMN users int NOT NULL DEFAULT 1,
ADD COLUMN posts int NOT NULL DEFAULT 0,
ADD COLUMN comments int NOT NULL DEFAULT 0,
ADD COLUMN communities int NOT NULL DEFAULT 0,
ADD COLUMN users_active_day int NOT NULL DEFAULT 0,
ADD COLUMN users_active_week int NOT NULL DEFAULT 0,
ADD COLUMN users_active_month int NOT NULL DEFAULT 0,
ADD COLUMN users_active_half_year int NOT NULL DEFAULT 0;
-- Disable the triggers temporarily
ALTER TABLE local_site DISABLE TRIGGER ALL;
-- disable all table indexes
UPDATE
pg_index
SET
indisready = FALSE
WHERE
indrelid = (
SELECT
oid
FROM
pg_class
WHERE
relname = 'local_site');
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
UPDATE
local_site
SET
users = sa.users,
posts = sa.posts,
comments = sa.comments,
communities = sa.communities,
users_active_day = sa.users_active_day,
users_active_week = sa.users_active_week,
users_active_month = sa.users_active_month,
users_active_half_year = sa.users_active_half_year
FROM
site_aggregates AS sa
WHERE
local_site.site_id = sa.site_id;
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
DROP TABLE site_aggregates;
-- Re-enable triggers after upserts
ALTER TABLE local_site ENABLE TRIGGER ALL;
-- Re-enable indexes
UPDATE
pg_index
SET
indisready = TRUE
WHERE
indrelid = (
SELECT
oid
FROM
pg_class
WHERE
relname = 'local_site');
-- reindex
REINDEX TABLE local_site;
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
-- merge local_user_vote_display_mode into local_user table
ALTER TABLE local_user
ADD COLUMN show_score boolean NOT NULL DEFAULT FALSE,
ADD COLUMN show_upvotes boolean NOT NULL DEFAULT TRUE,
ADD COLUMN show_downvotes boolean NOT NULL DEFAULT TRUE,
ADD COLUMN show_upvote_percentage boolean NOT NULL DEFAULT FALSE;
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
-- Disable the triggers temporarily
ALTER TABLE local_user DISABLE TRIGGER ALL;
-- disable all table indexes
UPDATE
pg_index
SET
indisready = FALSE
WHERE
indrelid = (
SELECT
oid
FROM
pg_class
WHERE
relname = 'local_user');
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00
UPDATE
local_user
SET
show_score = v.score,
show_upvotes = v.upvotes,
show_downvotes = v.downvotes,
show_upvote_percentage = v.upvote_percentage
FROM
local_user_vote_display_mode AS v
WHERE
local_user.id = v.local_user_id;
Fast history no background (#5873) * Finishing up post and comment actions * Adding community_actions. * instance and person actions * Fixing person_actions. * Fixing down migrations * Adding person_content_combined. * Search combined. * Aggregates tables. * Dont rename old tables * Fixing some constraints. * Convert bigints to ints * Forgot a bigint. * Rest of i64 -> i32 * Adding actions id columns. * Fixing connection config. * Formatting smoosh up.sql * Use current_date instead of now * Adding history tables for liked_combined * Upping wal size * Fix clippy * Fixing clippy. * Fixing i64 * Getting rid of let mut conn * Adding the history status table. * Adding published indexes to speed up history. * Adding comment like history scanning. * Fixing schema options setup. * post_read history * person_post_aggregates / read_comments history * post_like history * Fixing conflicts. * Fixing clippy. * Use constant batch_size. * person content combined post and comment history. * Fixing id scanning. * post/comment_actions -> saved_combined history * search history * Post and comment aggregates -> post / comment history. * Uncommenting full history building. * Changing DB_BATCH_SIZE to i64 * Fixing clippy. * Fix index names. * Fixing diff check by removing indexes. * Adding the uplete ignore actions::id columns. * Fixing merge imports. * Fixing submodule update * Try trigger disabling. * Fix clippy * Remove history table, do faster bulk inserts. Smoosh first. Comments about how this fast insert is done is within smoosh comments. * Adding some timings. * Fast person content combined history * Adding search_combined * Fix person saved combined unique names * person_liked_combined * Remove-aggregates * Fixing up.sql issues * Re-building schema.rs * Fixing down migrations. * Removing history updating. * Format sql. * Move postgres logging to customPostgresql.conf * Try using postgres 16-alpine in CI * Speeding up add_report_count. * speed up inbox_combined * Speeding up remove_post_sort_type_enums * Fixing post_sort_type * Speeding up person votes * Fixing wrong conn. * Fixing broken migrations * Remove comment. * Make sure to re-index table after re-enabling indexes. * Removing id columns from actions tables. * Fixing down migrations. * Using create table as for smoosh migration * create_table as for person_content_combined. * Fixing person_content_combined uniques * create table as for search_combined * create table as for liked_combined * create table as for inbox_combined. * Fixing a few score types. * Fixing id positions.
2025-07-23 21:43:23 +00:00
DROP TABLE local_user_vote_display_mode;
-- Re-enable triggers after upserts
ALTER TABLE local_user ENABLE TRIGGER ALL;
-- Re-enable indexes
UPDATE
pg_index
SET
indisready = TRUE
WHERE
indrelid = (
SELECT
oid
FROM
pg_class
WHERE
relname = 'local_user');
-- reindex
REINDEX TABLE local_user;
Remove aggregate tables (fixes #4869) (#5407) * migration * update code * tests * triggers * fix * fmt * clippy * post aggregate migration * changes for post aggregate code * wip: update tests for post aggregate * format * fix partialeq * trigger fix * fix post insert trigger * wip * reorder * fixes * community aggregate migration * update code * triggers * person aggregate migration * person aggregate code * person triggers * test fixes * fix scheduled task * update api tests * site_aggregates to local_site migration * site_aggregates code changes * triggers, tests * more fixes * Rename PersonPostAggregates to PostActions * Merge local_user_vote_display_mode into local_user * fix schema * remove duplicate fields * remove "aggregates" from index names * uncomment indices * if count = 0 * remove commentaggregates * Fix triggers in remove aggregates tables pr (#5451) * prevent all db_schema test errors * fix the delete_comments_before_post problem in a way that doesn't affect the returned number of affected rows * remove unnecessary recursion checks and add comment to remaining check * clean up * Fixing SQL format. * Update triggers.sql * Update triggers.sql * Update triggers.sql * Update triggers.sql * remove update of deleted column --------- Co-authored-by: Dessalines <tyhou13@gmx.com> * rename migration * Fix migration errors * Fixing person_saved_combined. (#5481) --------- Co-authored-by: dullbananas <dull.bananas0@gmail.com> Co-authored-by: Dessalines <tyhou13@gmx.com> Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
2025-03-06 15:18:41 +00:00