fix some things

This commit is contained in:
Dull Bananas 2023-12-28 18:22:59 +00:00
parent ebfe60cfdb
commit 4b9f4ce043

View File

@ -194,9 +194,9 @@ BEGIN
post_id,
creator_id,
local,
sum(count_diff) AS comments,
sum(count_diff) AS comments
FROM
combine_transition_tables ()
r.combine_transition_tables ()
WHERE
NOT (deleted
OR removed)
@ -235,8 +235,7 @@ post_diff AS (
max(published)
FROM new_table AS new_comment
WHERE
a.post_id = new_comment.post_id)
LIMIT 1),
a.post_id = new_comment.post_id LIMIT 1)),
newest_comment_time_necro = GREATEST (a.newest_comment_time_necro, (
SELECT
max(published)
@ -297,9 +296,9 @@ BEGIN
community_id,
creator_id,
local,
sum(count_diff) AS posts,
sum(count_diff) AS posts
FROM
combine_transition_tables ()
r.combine_transition_tables ()
WHERE
NOT (deleted
OR removed)
@ -341,7 +340,7 @@ $$;
CALL r.create_triggers ('post', 'parent_aggregates_from_post');
CREATE FUNCTION site_aggregates_from_community ()
CREATE FUNCTION r.site_aggregates_from_community ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
@ -354,17 +353,18 @@ BEGIN
SELECT
sum(change_diff) AS communities
FROM
combine_transition_tables ()
r.combine_transition_tables ()
WHERE
local
AND NOT (deleted
OR removed)) AS diff;
RETURN NULL;
END
$$;
CALL rcreate_triggers ('community', 'site_aggregates_from_community');
CALL r.create_triggers ('community', 'site_aggregates_from_community');
CREATE FUNCTION site_aggregates_from_person ()
CREATE FUNCTION r.site_aggregates_from_person ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
@ -377,10 +377,11 @@ BEGIN
SELECT
sum(change_diff) AS users
FROM
combine_transition_tables ()
r.combine_transition_tables ()
WHERE
local) AS diff;
RETURN NULL;
END
$$;
CALL r.create_triggers ('person', 'site_aggregates_from_person');
@ -424,11 +425,11 @@ BEGIN
WHERE
a.community_id = diff.community_id;
RETURN NULL;
END
$$;
CREATE TRIGGER comment_count
AFTER UPDATE OF deleted,
removed ON post REFERENCING OLD TABLE AS old_post NEW TABLE AS new_post
AFTER UPDATE ON post REFERENCING OLD TABLE AS old_post NEW TABLE AS new_post
FOR EACH STATEMENT
EXECUTE FUNCTION r.update_comment_count_from_post ();
@ -447,7 +448,7 @@ BEGIN
community_id,
sum(count_diff) AS subscribers
FROM
combine_transition_tables ()
r.combine_transition_tables ()
WHERE (
SELECT
local
@ -515,7 +516,7 @@ CREATE FUNCTION r.person_aggregates_from_person ()
BEGIN
INSERT INTO person_aggregates (person_id)
SELECT
id,
id
FROM
new_person;
RETURN NULL;
@ -592,13 +593,14 @@ CREATE FUNCTION r.site_aggregates_from_site ()
BEGIN
-- we only ever want to have a single value in site_aggregate because the site_aggregate triggers update all rows in that table.
-- a cleaner check would be to insert it for the local_site but that would break assumptions at least in the tests
IF NOT EXISTS (
IF (NOT EXISTS (
SELECT
1
FROM
site_aggregates) THEN
site_aggregates)) THEN
INSERT INTO site_aggregates (site_id)
VALUES (NEW.id);
END IF;
RETURN NULL;
END
$$;