mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
fix some things
This commit is contained in:
parent
ebfe60cfdb
commit
4b9f4ce043
@ -194,9 +194,9 @@ BEGIN
|
|||||||
post_id,
|
post_id,
|
||||||
creator_id,
|
creator_id,
|
||||||
local,
|
local,
|
||||||
sum(count_diff) AS comments,
|
sum(count_diff) AS comments
|
||||||
FROM
|
FROM
|
||||||
combine_transition_tables ()
|
r.combine_transition_tables ()
|
||||||
WHERE
|
WHERE
|
||||||
NOT (deleted
|
NOT (deleted
|
||||||
OR removed)
|
OR removed)
|
||||||
@ -235,8 +235,7 @@ post_diff AS (
|
|||||||
max(published)
|
max(published)
|
||||||
FROM new_table AS new_comment
|
FROM new_table AS new_comment
|
||||||
WHERE
|
WHERE
|
||||||
a.post_id = new_comment.post_id)
|
a.post_id = new_comment.post_id LIMIT 1)),
|
||||||
LIMIT 1),
|
|
||||||
newest_comment_time_necro = GREATEST (a.newest_comment_time_necro, (
|
newest_comment_time_necro = GREATEST (a.newest_comment_time_necro, (
|
||||||
SELECT
|
SELECT
|
||||||
max(published)
|
max(published)
|
||||||
@ -297,9 +296,9 @@ BEGIN
|
|||||||
community_id,
|
community_id,
|
||||||
creator_id,
|
creator_id,
|
||||||
local,
|
local,
|
||||||
sum(count_diff) AS posts,
|
sum(count_diff) AS posts
|
||||||
FROM
|
FROM
|
||||||
combine_transition_tables ()
|
r.combine_transition_tables ()
|
||||||
WHERE
|
WHERE
|
||||||
NOT (deleted
|
NOT (deleted
|
||||||
OR removed)
|
OR removed)
|
||||||
@ -341,7 +340,7 @@ $$;
|
|||||||
|
|
||||||
CALL r.create_triggers ('post', 'parent_aggregates_from_post');
|
CALL r.create_triggers ('post', 'parent_aggregates_from_post');
|
||||||
|
|
||||||
CREATE FUNCTION site_aggregates_from_community ()
|
CREATE FUNCTION r.site_aggregates_from_community ()
|
||||||
RETURNS TRIGGER
|
RETURNS TRIGGER
|
||||||
LANGUAGE plpgsql
|
LANGUAGE plpgsql
|
||||||
AS $$
|
AS $$
|
||||||
@ -354,17 +353,18 @@ BEGIN
|
|||||||
SELECT
|
SELECT
|
||||||
sum(change_diff) AS communities
|
sum(change_diff) AS communities
|
||||||
FROM
|
FROM
|
||||||
combine_transition_tables ()
|
r.combine_transition_tables ()
|
||||||
WHERE
|
WHERE
|
||||||
local
|
local
|
||||||
AND NOT (deleted
|
AND NOT (deleted
|
||||||
OR removed)) AS diff;
|
OR removed)) AS diff;
|
||||||
RETURN NULL;
|
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
|
RETURNS TRIGGER
|
||||||
LANGUAGE plpgsql
|
LANGUAGE plpgsql
|
||||||
AS $$
|
AS $$
|
||||||
@ -377,10 +377,11 @@ BEGIN
|
|||||||
SELECT
|
SELECT
|
||||||
sum(change_diff) AS users
|
sum(change_diff) AS users
|
||||||
FROM
|
FROM
|
||||||
combine_transition_tables ()
|
r.combine_transition_tables ()
|
||||||
WHERE
|
WHERE
|
||||||
local) AS diff;
|
local) AS diff;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
|
END
|
||||||
$$;
|
$$;
|
||||||
|
|
||||||
CALL r.create_triggers ('person', 'site_aggregates_from_person');
|
CALL r.create_triggers ('person', 'site_aggregates_from_person');
|
||||||
@ -424,11 +425,11 @@ BEGIN
|
|||||||
WHERE
|
WHERE
|
||||||
a.community_id = diff.community_id;
|
a.community_id = diff.community_id;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
|
END
|
||||||
$$;
|
$$;
|
||||||
|
|
||||||
CREATE TRIGGER comment_count
|
CREATE TRIGGER comment_count
|
||||||
AFTER UPDATE OF deleted,
|
AFTER UPDATE ON post REFERENCING OLD TABLE AS old_post NEW TABLE AS new_post
|
||||||
removed ON post REFERENCING OLD TABLE AS old_post NEW TABLE AS new_post
|
|
||||||
FOR EACH STATEMENT
|
FOR EACH STATEMENT
|
||||||
EXECUTE FUNCTION r.update_comment_count_from_post ();
|
EXECUTE FUNCTION r.update_comment_count_from_post ();
|
||||||
|
|
||||||
@ -447,7 +448,7 @@ BEGIN
|
|||||||
community_id,
|
community_id,
|
||||||
sum(count_diff) AS subscribers
|
sum(count_diff) AS subscribers
|
||||||
FROM
|
FROM
|
||||||
combine_transition_tables ()
|
r.combine_transition_tables ()
|
||||||
WHERE (
|
WHERE (
|
||||||
SELECT
|
SELECT
|
||||||
local
|
local
|
||||||
@ -515,7 +516,7 @@ CREATE FUNCTION r.person_aggregates_from_person ()
|
|||||||
BEGIN
|
BEGIN
|
||||||
INSERT INTO person_aggregates (person_id)
|
INSERT INTO person_aggregates (person_id)
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id
|
||||||
FROM
|
FROM
|
||||||
new_person;
|
new_person;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@ -592,13 +593,14 @@ CREATE FUNCTION r.site_aggregates_from_site ()
|
|||||||
BEGIN
|
BEGIN
|
||||||
-- we only ever want to have a single value in site_aggregate because the site_aggregate triggers update all rows in that table.
|
-- 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
|
-- 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
|
SELECT
|
||||||
1
|
1
|
||||||
FROM
|
FROM
|
||||||
site_aggregates) THEN
|
site_aggregates)) THEN
|
||||||
INSERT INTO site_aggregates (site_id)
|
INSERT INTO site_aggregates (site_id)
|
||||||
VALUES (NEW.id);
|
VALUES (NEW.id);
|
||||||
|
END IF;
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
END
|
END
|
||||||
$$;
|
$$;
|
||||||
|
Loading…
Reference in New Issue
Block a user