mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-13 22:22:10 +00:00
Merge branch 'combined_profile' into combined_modlog
This commit is contained in:
commit
6363e7d5db
|
@ -714,74 +714,50 @@ CALL r.create_person_content_combined_trigger ('post');
|
||||||
CALL r.create_person_content_combined_trigger ('comment');
|
CALL r.create_person_content_combined_trigger ('comment');
|
||||||
|
|
||||||
-- person_saved (comment, post)
|
-- person_saved (comment, post)
|
||||||
-- TODO, not sure how to handle changes to post_actions and comment_actions.saved column using @dullbanana's trigger method.
|
-- This one is a little different, because it triggers using x_actions.saved,
|
||||||
-- Post
|
-- Rather than any row insert
|
||||||
CREATE FUNCTION r.person_saved_combined_change_values_post ()
|
CREATE PROCEDURE r.create_person_saved_combined_trigger (table_name text)
|
||||||
RETURNS TRIGGER
|
LANGUAGE plpgsql
|
||||||
LANGUAGE plpgsql
|
AS $a$
|
||||||
AS $$
|
|
||||||
BEGIN
|
BEGIN
|
||||||
IF (TG_OP = 'DELETE') THEN
|
EXECUTE replace($b$ CREATE FUNCTION r.person_saved_combined_change_values_thing ( )
|
||||||
DELETE FROM person_saved_combined AS p
|
RETURNS TRIGGER
|
||||||
WHERE p.person_id = OLD.person_id
|
LANGUAGE plpgsql
|
||||||
AND p.post_id = OLD.post_id;
|
AS $$
|
||||||
ELSIF (TG_OP = 'INSERT') THEN
|
BEGIN
|
||||||
IF NEW.saved IS NOT NULL THEN
|
IF (TG_OP = 'DELETE') THEN
|
||||||
INSERT INTO person_saved_combined (published, person_id, post_id)
|
DELETE FROM person_saved_combined AS p
|
||||||
VALUES (NEW.saved, NEW.person_id, NEW.post_id);
|
WHERE p.person_id = OLD.person_id
|
||||||
END IF;
|
AND p.thing_id = OLD.thing_id;
|
||||||
ELSIF (TG_OP = 'UPDATE') THEN
|
ELSIF (TG_OP = 'INSERT') THEN
|
||||||
IF NEW.saved IS NOT NULL THEN
|
IF NEW.saved IS NOT NULL THEN
|
||||||
INSERT INTO person_saved_combined (published, person_id, post_id)
|
INSERT INTO person_saved_combined (published, person_id, thing_id)
|
||||||
VALUES (NEW.saved, NEW.person_id, NEW.post_id);
|
VALUES (NEW.saved, NEW.person_id, NEW.thing_id);
|
||||||
-- If saved gets set as null, delete the row
|
END IF;
|
||||||
ELSE
|
ELSIF (TG_OP = 'UPDATE') THEN
|
||||||
DELETE FROM person_saved_combined AS p
|
IF NEW.saved IS NOT NULL THEN
|
||||||
WHERE p.person_id = NEW.person_id
|
INSERT INTO person_saved_combined (published, person_id, thing_id)
|
||||||
AND p.post_id = NEW.post_id;
|
VALUES (NEW.saved, NEW.person_id, NEW.thing_id);
|
||||||
END IF;
|
-- If saved gets set as null, delete the row
|
||||||
END IF;
|
ELSE
|
||||||
RETURN NULL;
|
DELETE FROM person_saved_combined AS p
|
||||||
END
|
WHERE p.person_id = NEW.person_id
|
||||||
$$;
|
AND p.thing_id = NEW.thing_id;
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
RETURN NULL;
|
||||||
|
END $$;
|
||||||
|
CREATE TRIGGER person_saved_combined
|
||||||
|
AFTER INSERT OR DELETE OR UPDATE OF saved ON thing_actions
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION r.person_saved_combined_change_values_thing ( );
|
||||||
|
$b$,
|
||||||
|
'thing',
|
||||||
|
table_name);
|
||||||
|
END;
|
||||||
|
$a$;
|
||||||
|
|
||||||
CREATE TRIGGER person_saved_combined_post
|
CALL r.create_person_saved_combined_trigger ('post');
|
||||||
AFTER INSERT OR DELETE OR UPDATE OF saved ON post_actions
|
|
||||||
FOR EACH ROW
|
|
||||||
EXECUTE FUNCTION r.person_saved_combined_change_values_post ();
|
|
||||||
|
|
||||||
-- Comment
|
CALL r.create_person_saved_combined_trigger ('comment');
|
||||||
CREATE FUNCTION r.person_saved_combined_change_values_comment ()
|
|
||||||
RETURNS TRIGGER
|
|
||||||
LANGUAGE plpgsql
|
|
||||||
AS $$
|
|
||||||
BEGIN
|
|
||||||
IF (TG_OP = 'DELETE') THEN
|
|
||||||
DELETE FROM person_saved_combined AS p
|
|
||||||
WHERE p.person_id = OLD.person_id
|
|
||||||
AND p.comment_id = OLD.comment_id;
|
|
||||||
ELSIF (TG_OP = 'INSERT') THEN
|
|
||||||
IF NEW.saved IS NOT NULL THEN
|
|
||||||
INSERT INTO person_saved_combined (published, person_id, comment_id)
|
|
||||||
VALUES (NEW.saved, NEW.person_id, NEW.comment_id);
|
|
||||||
END IF;
|
|
||||||
ELSIF (TG_OP = 'UPDATE') THEN
|
|
||||||
IF NEW.saved IS NOT NULL THEN
|
|
||||||
INSERT INTO person_saved_combined (published, person_id, comment_id)
|
|
||||||
VALUES (NEW.saved, NEW.person_id, NEW.comment_id);
|
|
||||||
-- If saved gets set as null, delete the row
|
|
||||||
ELSE
|
|
||||||
DELETE FROM person_saved_combined AS p
|
|
||||||
WHERE p.person_id = NEW.person_id
|
|
||||||
AND p.comment_id = NEW.comment_id;
|
|
||||||
END IF;
|
|
||||||
END IF;
|
|
||||||
RETURN NULL;
|
|
||||||
END
|
|
||||||
$$;
|
|
||||||
|
|
||||||
CREATE TRIGGER person_saved_combined_comment
|
|
||||||
AFTER INSERT OR DELETE OR UPDATE OF saved ON comment_actions
|
|
||||||
FOR EACH ROW
|
|
||||||
EXECUTE FUNCTION r.person_saved_combined_change_values_comment ();
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue