-
-
Save davidfetter/a939d8a1c6efb650a1a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION fessup.fetch_posts_for_my_timeline( | |
fesser_id bigint, | |
last_id bigint DEFAULT 0, | |
newer boolean DEFAULT true | |
) | |
RETURNS SETOF fessup.all_posts | |
AS $$ | |
BEGIN | |
RETURN QUERY | |
WITH | |
feeds_i_have_blocked AS ( | |
SELECT * FROM fessup.feed_block WHERE blocker = fesser_id | |
), | |
myself_and_other_fessers_whose_posts_i_want_to_see AS ( | |
SELECT fesser_id UNION ALL | |
SELECT followee FROM fessup.following | |
WHERE follower = fesser_id | |
AND during @> now() | |
AND NOT EXISTS ( SELECT * FROM feeds_i_have_blocked WHERE blockee = followee ) | |
) | |
SELECT * | |
FROM fessup.all_posts a | |
WHERE ((newer AND a.id > last_id) OR (NOT newer AND a.id < last_id)) | |
AND a.author IN ( SELECT * FROM myself_and_other_fessers_whose_posts_i_want_to_see ) | |
ORDER BY a.id DESC | |
LIMIT 40; | |
END;; | |
$$ LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment