diff --git a/hive/db/sql_scripts/update_hive_posts_children_count.sql b/hive/db/sql_scripts/update_hive_posts_children_count.sql index 83ea5c5b3b473a447a4971ac6fe805b312440238..1a91e44bf1481e47f6719ac63a767559b91d3ce8 100644 --- a/hive/db/sql_scripts/update_hive_posts_children_count.sql +++ b/hive/db/sql_scripts/update_hive_posts_children_count.sql @@ -67,17 +67,18 @@ CREATE OR REPLACE FUNCTION public.update_all_hive_posts_children_count() LANGUAGE 'plpgsql' VOLATILE AS $BODY$ -declare __depth int; +declare __depth INT; BEGIN SELECT MAX(hp.depth) into __depth FROM hive_posts hp ; - DROP TABLE if exists __post_children; - create unlogged table __post_children + CREATE UNLOGGED TABLE IF NOT EXISTS __post_children ( - id int not null, - child_count int not null, - CONSTRAINT __post_children2_pkey PRIMARY KEY (id) + id INT NOT NULL, + child_count INT NOT NULL, + CONSTRAINT __post_children_pkey PRIMARY KEY (id) ); + + TRUNCATE TABLE __post_children; WHILE __depth >= 0 LOOP INSERT INTO __post_children @@ -92,7 +93,7 @@ BEGIN WHERE (h1.parent_id != 0 OR __depth = 0) AND h1.counter_deleted = 0 AND h1.id != 0 AND h1.depth = __depth GROUP BY h1.parent_id - ON CONFLICT ON CONSTRAINT __post_children2_pkey DO UPDATE + ON CONFLICT ON CONSTRAINT __post_children_pkey DO UPDATE SET child_count = __post_children.child_count + excluded.child_count ; diff --git a/hive/indexer/follow.py b/hive/indexer/follow.py index a4d2930cb1fbf07b35af3b939778c57097034098..131f07dcd2a219a6635321f0f2a1fa68214d95c2 100644 --- a/hive/indexer/follow.py +++ b/hive/indexer/follow.py @@ -277,7 +277,7 @@ class Follow(DbAdapterHolder): UPDATE hive_follows hf SET - hf.blacklisted = false + blacklisted = false FROM ( SELECT @@ -298,7 +298,7 @@ class Follow(DbAdapterHolder): UPDATE hive_follows hf SET - hf.state = 0 + state = 0 FROM ( SELECT @@ -320,7 +320,7 @@ class Follow(DbAdapterHolder): UPDATE hive_follows hf SET - hf.state = 0 + state = 0 FROM ( SELECT @@ -342,7 +342,7 @@ class Follow(DbAdapterHolder): UPDATE hive_follows hf SET - hf.follow_blacklists = false + follow_blacklists = false FROM ( SELECT @@ -383,7 +383,7 @@ class Follow(DbAdapterHolder): UPDATE hive_follows hf SET - hf.follow_muted = false + follow_muted = false FROM ( SELECT @@ -401,7 +401,7 @@ class Follow(DbAdapterHolder): UPDATE hive_follows hf SET - hf.follow_muted = true + follow_muted = true FROM ( SELECT @@ -423,10 +423,10 @@ class Follow(DbAdapterHolder): UPDATE hive_follows hf SET - hf.blacklisted = false, - hf.follow_blacklists = false, - hf.follow_muted = false, - hf.state = 0 + blacklisted = false, + follow_blacklists = false, + follow_muted = false, + state = 0 FROM ( SELECT @@ -444,8 +444,8 @@ class Follow(DbAdapterHolder): UPDATE hive_follows hf SET - hf.follow_blacklists = true, - hf.follow_muted = true + follow_blacklists = true, + follow_muted = true FROM ( SELECT