diff --git a/schema.sql b/schema.sql index 92ab1d7e8..768e3a36e 100644 --- a/schema.sql +++ b/schema.sql @@ -19,7 +19,6 @@ SET row_security = off; ALTER TABLE ONLY public.users DROP CONSTRAINT users_title_fkey; ALTER TABLE ONLY public.subscriptions DROP CONSTRAINT subscriptions_board_id_fkey; ALTER TABLE ONLY public.submissions DROP CONSTRAINT submissions_original_board_id_fkey; -ALTER TABLE ONLY public.submissions DROP CONSTRAINT submissions_board_id_fkey; ALTER TABLE ONLY public.subcategories DROP CONSTRAINT subcategories_cat_id_fkey; ALTER TABLE ONLY public.reports DROP CONSTRAINT reports_post_id_fkey; ALTER TABLE ONLY public.postrels DROP CONSTRAINT postrels_post_id_fkey; @@ -62,11 +61,9 @@ DROP INDEX public.submissions_score_idx; DROP INDEX public.submissions_over18_index; DROP INDEX public.submissions_offensive_index; DROP INDEX public.submissions_created_utc_desc_idx; -DROP INDEX public.submissions_board_index; DROP INDEX public.submissions_aux_title_idx; DROP INDEX public.submissions_aux_id_idx; DROP INDEX public.submissions_author_index; -DROP INDEX public.submission_time_board_idx; DROP INDEX public.submission_purge_idx; DROP INDEX public.submission_pinned_idx; DROP INDEX public.submission_original_board_id_idx; @@ -77,14 +74,9 @@ DROP INDEX public.submission_ip_idx; DROP INDEX public.submission_hot_sort_idx; DROP INDEX public.submission_domainref_index; DROP INDEX public.submission_disputed_sort_idx; -DROP INDEX public.submission_best_sort_idx; DROP INDEX public.submission_best_only_idx; DROP INDEX public.submission_aux_url_trgm_idx; DROP INDEX public.submission_aux_url_idx; -DROP INDEX public.submission_activity_top_idx; -DROP INDEX public.submission_activity_sort_idx; -DROP INDEX public.submission_activity_hot_idx; -DROP INDEX public.submission_activity_disputed_idx; DROP INDEX public.subimssion_binary_group_idx; DROP INDEX public.sub_user_index; DROP INDEX public.sub_active_index; @@ -107,7 +99,6 @@ DROP INDEX public.notification_read_idx; DROP INDEX public.modaction_pid_idx; DROP INDEX public.modaction_id_idx; DROP INDEX public.modaction_cid_idx; -DROP INDEX public.modaction_board_idx; DROP INDEX public.modaction_action_idx; DROP INDEX public.mod_user_index; DROP INDEX public.mod_rescind_index; @@ -422,7 +413,7 @@ DROP FUNCTION public.rank_activity(public.submissions); DROP FUNCTION public.mod_count(public.users); DROP FUNCTION public.is_public(public.submissions); DROP FUNCTION public.is_public(public.comments); -DROP FUNCTION public.deleted_utc(public.notifications); +DROP FUNCTION public.is_deleted(public.notifications); DROP FUNCTION public.is_banned(public.notifications); DROP FUNCTION public.follower_count(public.users); DROP FUNCTION public.flag_count(public.submissions); @@ -543,12 +534,9 @@ ALTER TABLE public.boards OWNER TO postgres; CREATE FUNCTION public.age(public.boards) RETURNS integer LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - - - SELECT CAST( EXTRACT( EPOCH FROM CURRENT_TIMESTAMP) AS int) - $1.created_utc - + AS $_$ + + SELECT CAST( EXTRACT( EPOCH FROM CURRENT_TIMESTAMP) AS int) - $1.created_utc $_$; @@ -567,7 +555,7 @@ CREATE TABLE public.comments ( parent_fullname character varying(255), distinguish_level integer, edited_utc integer, - deleted_utc > 0 integer NOT NULL, + deleted_utc integer NOT NULL, is_approved integer NOT NULL, author_name character varying(64), approved_utc integer, @@ -605,10 +593,8 @@ ALTER TABLE public.comments OWNER TO postgres; CREATE FUNCTION public.age(public.comments) RETURNS integer LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT CAST( EXTRACT( EPOCH FROM CURRENT_TIMESTAMP) AS int) - $1.created_utc - + AS $_$ + SELECT CAST( EXTRACT( EPOCH FROM CURRENT_TIMESTAMP) AS int) - $1.created_utc $_$; @@ -627,8 +613,7 @@ CREATE TABLE public.submissions ( distinguish_level integer, created_str character varying(255), stickied boolean, - board_id integer, - deleted_utc > 0 integer NOT NULL, + deleted_utc integer NOT NULL, domain_ref integer, is_approved integer NOT NULL, approved_utc integer, @@ -671,10 +656,8 @@ ALTER TABLE public.submissions OWNER TO postgres; CREATE FUNCTION public.age(public.submissions) RETURNS integer LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT CAST( EXTRACT( EPOCH FROM CURRENT_TIMESTAMP) AS int) - $1.created_utc - + AS $_$ + SELECT CAST( EXTRACT( EPOCH FROM CURRENT_TIMESTAMP) AS int) - $1.created_utc $_$; @@ -704,7 +687,6 @@ CREATE TABLE public.users ( login_nonce integer, title_id integer, has_banner boolean NOT NULL, - has_profile boolean NOT NULL, reserved character varying(256), is_nsfw boolean NOT NULL, tos_agreed_utc integer, @@ -713,7 +695,7 @@ CREATE TABLE public.users ( last_siege_utc integer, mfa_secret character varying(32), has_earned_darkmode boolean, - deleted_utc > 0 boolean, + is_private boolean, read_announcement_utc integer, feed_nonce integer, show_nsfl boolean, @@ -787,10 +769,8 @@ ALTER TABLE public.users OWNER TO postgres; CREATE FUNCTION public.age(public.users) RETURNS integer LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT CAST( EXTRACT( EPOCH FROM CURRENT_TIMESTAMP) AS int) - $1.created_utc - + AS $_$ + SELECT CAST( EXTRACT( EPOCH FROM CURRENT_TIMESTAMP) AS int) - $1.created_utc $_$; @@ -802,22 +782,14 @@ ALTER FUNCTION public.age(public.users) OWNER TO postgres; CREATE FUNCTION public.avg_score_computed(public.boards) RETURNS numeric LANGUAGE sql IMMUTABLE STRICT - AS $_$ - -select coalesce ( - - (select avg(score_top) from submissions - - where original_board_id=$1.id - - and score_top>0) - - , - - 1 - - ) - + AS $_$ +select coalesce ( + (select avg(score_top) from submissions + where original_board_id=$1.id + and score_top>0) + , + 1 + ) $_$; @@ -829,14 +801,10 @@ ALTER FUNCTION public.avg_score_computed(public.boards) OWNER TO postgres; CREATE FUNCTION public.board_id(public.comments) RETURNS integer LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT submissions.board_id - - FROM submissions - - WHERE submissions.id=$1.parent_submission - + AS $_$ + SELECT submissions.board_id + FROM submissions + WHERE submissions.id=$1.parent_submission $_$; @@ -862,14 +830,10 @@ ALTER TABLE public.reports OWNER TO postgres; CREATE FUNCTION public.board_id(public.reports) RETURNS integer LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT submissions.board_id - - FROM submissions - - WHERE submissions.id=$1.post_id - + AS $_$ + SELECT submissions.board_id + FROM submissions + WHERE submissions.id=$1.post_id $_$; @@ -906,28 +870,17 @@ ALTER FUNCTION public.comment_count(public.submissions) OWNER TO postgres; CREATE FUNCTION public.comment_energy(public.users) RETURNS bigint LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT COALESCE( - - ( - - SELECT SUM(comments.score_top) - - FROM comments - - WHERE comments.author_id=$1.id - - AND comments.is_banned=false - - and comments.parent_submission is not null - - ), - - 0 - - ) - + AS $_$ + SELECT COALESCE( + ( + SELECT SUM(comments.score_top) + FROM comments + WHERE comments.author_id=$1.id + AND comments.is_banned=false + and comments.parent_submission is not null + ), + 0 + ) $_$; @@ -957,12 +910,9 @@ ALTER TABLE public.notifications OWNER TO postgres; CREATE FUNCTION public.created_utc(public.notifications) RETURNS integer LANGUAGE sql IMMUTABLE STRICT - AS $_$ - -select created_utc from comments - -where comments.id=$1.comment_id - + AS $_$ +select created_utc from comments +where comments.id=$1.comment_id $_$; @@ -974,116 +924,61 @@ ALTER FUNCTION public.created_utc(public.notifications) OWNER TO postgres; CREATE FUNCTION public.downs(public.comments) RETURNS bigint LANGUAGE sql - AS $_$ - -select ( - -( - - SELECT count(*) - - from ( - - select * from commentvotes - - where comment_id=$1.id - - and vote_type=-1 - - and user_id not in - - ( - - select user_id - - from bans - - where board_id=$1.original_board_id - - and is_active=true - - ) - - ) as v1 - - join (select * from users where users.is_banned=0 or users.unban_utc>0 - -) as u0 - - on u0.id=v1.user_id - -)-( - - SELECT count(distinct v1.id) - - from ( - - select * from commentvotes - - where comment_id=$1.id - - and vote_type=-1 - - and user_id not in - - ( - - select user_id - - from bans - - where board_id=$1.original_board_id - - and is_active=true - - ) - - ) as v1 - - join (select * from users where is_banned=0 or users.unban_utc>0) as u1 - - on u1.id=v1.user_id - - join (select * from alts) as a - - on (a.user1=v1.user_id or a.user2=v1.user_id) - - join ( - - select * from commentvotes - - where comment_id=$1.id - - and vote_type=-1 - - and user_id not in - - ( - - select user_id - - from bans - - where board_id=$1.original_board_id - - and is_active=true - - ) - - ) as v2 - - on ((a.user1=v2.user_id or a.user2=v2.user_id) and v2.id != v1.id) - - join (select * from users where is_banned=0 or users.unban_utc>0) as u2 - - on u2.id=v2.user_id - - where v1.id is not null - - and v2.id is not null - -)) - + AS $_$ +select ( +( + SELECT count(*) + from ( + select * from commentvotes + where comment_id=$1.id + and vote_type=-1 + and user_id not in + ( + select user_id + from bans + where board_id=$1.original_board_id + and is_active=true + ) + ) as v1 + join (select * from users where users.is_banned=0 or users.unban_utc>0 +) as u0 + on u0.id=v1.user_id +)-( + SELECT count(distinct v1.id) + from ( + select * from commentvotes + where comment_id=$1.id + and vote_type=-1 + and user_id not in + ( + select user_id + from bans + where board_id=$1.original_board_id + and is_active=true + ) + ) as v1 + join (select * from users where is_banned=0 or users.unban_utc>0) as u1 + on u1.id=v1.user_id + join (select * from alts) as a + on (a.user1=v1.user_id or a.user2=v1.user_id) + join ( + select * from commentvotes + where comment_id=$1.id + and vote_type=-1 + and user_id not in + ( + select user_id + from bans + where board_id=$1.original_board_id + and is_active=true + ) + ) as v2 + on ((a.user1=v2.user_id or a.user2=v2.user_id) and v2.id != v1.id) + join (select * from users where is_banned=0 or users.unban_utc>0) as u2 + on u2.id=v2.user_id + where v1.id is not null + and v2.id is not null +)) $_$; @@ -1095,114 +990,60 @@ ALTER FUNCTION public.downs(public.comments) OWNER TO postgres; CREATE FUNCTION public.downs(public.submissions) RETURNS bigint LANGUAGE sql - AS $_$ - -select ( - -( - - SELECT count(*) - - from ( - - select * from votes - - where submission_id=$1.id - - and vote_type=-1 - - and user_id not in - - ( - - select user_id - - from bans - - where board_id=$1.board_id - - and is_active=true - - ) - - ) as v1 - - join (select * from users where users.is_banned=0 or users.unban_utc>0) as u0 - - on u0.id=v1.usedeleted_utc - -)-( - - SELECT count(distinct v1.id) - - from ( - - select * from votes - - where submission_id=$1.id - - and vote_type=-1 - - and user_id not in - - ( - - select user_id - - from bans - - where board_id=$1.board_id - - and is_active=true - - ) - - ) as v1 - - join (select * from users where is_banned=0 or users.unban_utc>0) as u1 - - on u1.id=v1.user_id - - join (select * from alts) as a - - on (a.user1=v1.user_id or a.user2=v1.user_id) - - join ( - - select * from votes - - where submission_id=$1.id - - and vote_type=-1 - - and user_id not in - - (deleted_utc - - select user_id -deleted_utc - from bans - - whdeleted_utcid=$1.board_id - - and is_active=true - - ) -deleted_utc - ) as v2 - - on ((a.user1=v2.user_id or a.user2=v2.user_id) and v2.id != v1.id) - - join (select * from users where is_banned=0 or users.unban_utc>0) as u2 - - on u2.id=v2.user_id - - where v1.id is not null - - and v2.id is not null - -)) - + AS $_$ +select ( +( + SELECT count(*) + from ( + select * from votes + where submission_id=$1.id + and vote_type=-1 + and user_id not in + ( + select user_id + from bans + where board_id=$1.board_id + and is_active=true + ) + ) as v1 + join (select * from users where users.is_banned=0 or users.unban_utc>0) as u0 + on u0.id=v1.user_id +)-( + SELECT count(distinct v1.id) + from ( + select * from votes + where submission_id=$1.id + and vote_type=-1 + and user_id not in + ( + select user_id + from bans + where board_id=$1.board_id + and is_active=true + ) + ) as v1 + join (select * from users where is_banned=0 or users.unban_utc>0) as u1 + on u1.id=v1.user_id + join (select * from alts) as a + on (a.user1=v1.user_id or a.user2=v1.user_id) + join ( + select * from votes + where submission_id=$1.id + and vote_type=-1 + and user_id not in + ( + select user_id + from bans + where board_id=$1.board_id + and is_active=true + ) + ) as v2 + on ((a.user1=v2.user_id or a.user2=v2.user_id) and v2.id != v1.id) + join (select * from users where is_banned=0 or users.unban_utc>0) as u2 + on u2.id=v2.user_id + where v1.id is not null + and v2.id is not null +)) $_$; @@ -1214,26 +1055,16 @@ ALTER FUNCTION public.downs(public.submissions) OWNER TO postgres; CREATE FUNCTION public.energy(public.users) RETURNS bigint LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT COALESCE( - - ( - - SELECT SUM(submissions.score_top) - - FROM submissions - - WHERE submissions.author_id=$1.id - - AND submissions.is_banned=false - - ), - - 0 - - ) - + AS $_$ + SELECT COALESCE( + ( + SELECT SUM(submissions.score_top) + FROM submissions + WHERE submissions.author_id=$1.id + AND submissions.is_banned=false + ), + 0 + ) $_$; @@ -1245,18 +1076,12 @@ ALTER FUNCTION public.energy(public.users) OWNER TO postgres; CREATE FUNCTION public.flag_count(public.comments) RETURNS bigint LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT COUNT(*) - - FROM commentflags - - JOIN users ON commentflags.user_id=users.id - - WHERE comment_id=$1.id - - AND users.is_banned=0 - + AS $_$ + SELECT COUNT(*) + FROM commentflags + JOIN users ON commentflags.user_id=users.id + WHERE comment_id=$1.id + AND users.is_banned=0 $_$; @@ -1268,18 +1093,12 @@ ALTER FUNCTION public.flag_count(public.comments) OWNER TO postgres; CREATE FUNCTION public.flag_count(public.submissions) RETURNS bigint LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT COUNT(*) - - FROM flags - - JOIN users ON flags.user_id=users.id - - WHERE post_id=$1.id - - AND users.is_banned=0 - + AS $_$ + SELECT COUNT(*) + FROM flags + JOIN users ON flags.user_id=users.id + WHERE post_id=$1.id + AND users.is_banned=0 $_$; @@ -1291,78 +1110,42 @@ ALTER FUNCTION public.flag_count(public.submissions) OWNER TO postgres; CREATE FUNCTION public.follower_count(public.users) RETURNS bigint LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - select ( - - (select count(*) - - from follows - - left join users - - on follows.user_id=users.id - - where follows.target_id=$1.id - - and (users.is_banned=0 or users.created_utc>0) - - and users.is_deleted=false - - )-( - - select count(distinct f1.id) - - from - - ( - - select * - - from follows - - where target_id=$1.id - - ) as f1 - - join (select * from users where is_banned=0 or unban_utc>0) as u1 - - on u1.id=f1.user_id - - join (select * from alts) as a - - on (a.user1=f1.user_id or a.user2=f1.user_id) - - join ( - - select * - - from follows - - where target_id=$1.id - - ) as f2 - - on ((a.user1=f2.user_id or a.user2=f2.user_id) and f2.id != f1.id) - - join (select * from users where is_banned=0 or unban_utc>0) as u2 - - on u2.id=f2.user_id - - where f1.id is not null - - and f2.id is not null - - ) - - - - - - - - ) - + AS $_$ + select ( + (select count(*) + from follows + left join users + on follows.user_id=users.id + where follows.target_id=$1.id + and (users.is_banned=0 or users.created_utc>0) + and users.is_deleted=false + )-( + select count(distinct f1.id) + from + ( + select * + from follows + where target_id=$1.id + ) as f1 + join (select * from users where is_banned=0 or unban_utc>0) as u1 + on u1.id=f1.user_id + join (select * from alts) as a + on (a.user1=f1.user_id or a.user2=f1.user_id) + join ( + select * + from follows + where target_id=$1.id + ) as f2 + on ((a.user1=f2.user_id or a.user2=f2.user_id) and f2.id != f1.id) + join (select * from users where is_banned=0 or unban_utc>0) as u2 + on u2.id=f2.user_id + where f1.id is not null + and f2.id is not null + ) + + + + ) $_$; @@ -1374,12 +1157,9 @@ ALTER FUNCTION public.follower_count(public.users) OWNER TO postgres; CREATE FUNCTION public.is_banned(public.notifications) RETURNS boolean LANGUAGE sql IMMUTABLE STRICT - AS $_$ - -select is_banned from comments - -where comments.id=$1.comment_id - + AS $_$ +select is_banned from comments +where comments.id=$1.comment_id $_$; @@ -1391,12 +1171,9 @@ ALTER FUNCTION public.is_banned(public.notifications) OWNER TO postgres; CREATE FUNCTION public.is_deleted(public.notifications) RETURNS boolean LANGUAGE sql IMMUTABLE STRICT - AS $_$ - -select is_deleted from comments - -where comments.id=$1.comment_id - + AS $_$ +select is_deleted from comments +where comments.id=$1.comment_id $_$; @@ -1408,14 +1185,10 @@ ALTER FUNCTION public.is_deleted(public.notifications) OWNER TO postgres; CREATE FUNCTION public.is_public(public.comments) RETURNS boolean LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT submissions.is_public - - FROM submissions - - WHERE submissions.id=$1.parent_submission - + AS $_$ + SELECT submissions.is_public + FROM submissions + WHERE submissions.id=$1.parent_submission $_$; @@ -1427,43 +1200,28 @@ ALTER FUNCTION public.is_public(public.comments) OWNER TO postgres; CREATE FUNCTION public.is_public(public.submissions) RETURNS boolean LANGUAGE sql IMMUTABLE STRICT - AS $_$ - -select - - case - - when $1.post_public=true - - then true - - when (select (is_private) - - from boards - - where id=$1.board_id - - )=true - - then false - - else - - true - - end - - - - - + AS $_$ +select + case + when $1.post_public=true + then true + when (select (is_private) + from boards + where id=$1.board_id + )=true + then false + else + true + end + + $_$; ALTER FUNCTION public.is_public(public.submissions) OWNER TO postgres; -- --- Name: mod_count(pudeleted_utc); Type: FUNCTION; Schema: public; Owner: postgres +-- Name: mod_count(public.users); Type: FUNCTION; Schema: public; Owner: postgres -- CREATE FUNCTION public.mod_count(public.users) RETURNS bigint @@ -1479,10 +1237,8 @@ ALTER FUNCTION public.mod_count(public.users) OWNER TO postgres; CREATE FUNCTION public.rank_activity(public.submissions) RETURNS double precision LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT 1000000.0*CAST($1.comment_count AS float)/((CAST(($1.age+5000) AS FLOAT)/100.0)^(1.35)) - + AS $_$ + SELECT 1000000.0*CAST($1.comment_count AS float)/((CAST(($1.age+5000) AS FLOAT)/100.0)^(1.35)) $_$; @@ -1494,10 +1250,8 @@ ALTER FUNCTION public.rank_activity(public.submissions) OWNER TO postgres; CREATE FUNCTION public.rank_best(public.submissions) RETURNS double precision LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT 10000000.0*CAST(($1.upvotes - $1.downvotes + 1) AS float)/((CAST(($1.age+3600) AS FLOAT)*cast((select boards.subscriber_count from boards where boards.id=$1.board_id)+10000 as float)/1000.0)^(1.35)) - + AS $_$ + SELECT 10000000.0*CAST(($1.upvotes - $1.downvotes + 1) AS float)/((CAST(($1.age+3600) AS FLOAT)*cast((select boards.subscriber_count from boards where boards.id=$1.board_id)+10000 as float)/1000.0)^(1.35)) $_$; @@ -1509,10 +1263,8 @@ ALTER FUNCTION public.rank_best(public.submissions) OWNER TO postgres; CREATE FUNCTION public.rank_fiery(public.comments) RETURNS double precision LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT SQRT(CAST((deleted_utc > 0 * $1.downvotes) AS float)) - + AS $_$ + SELECT SQRT(CAST(($1.upvotes * $1.downvotes) AS float)) $_$; @@ -1524,10 +1276,8 @@ ALTER FUNCTION public.rank_fiery(public.comments) OWNER TO postgres; CREATE FUNCTION public.rank_fiery(public.submissions) RETURNS double precision LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT 1000000.0*SQRT(CAST(($1.upvotes * $1.downvotes) AS float))/((CAST(($1.age+5000) AS FLOAT)/100.0)^(1.35)) - + AS $_$ + SELECT 1000000.0*SQRT(CAST(($1.upvotes * $1.downvotes) AS float))/((CAST(($1.age+5000) AS FLOAT)/100.0)^(1.35)) $_$; @@ -1539,10 +1289,8 @@ ALTER FUNCTION public.rank_fiery(public.submissions) OWNER TO postgres; CREATE FUNCTION public.rank_hot(public.comments) RETURNS double precision LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT CAST(($1.upvotes - $1.downvotes) AS float)/((CAST(($1.age+100000) AS FLOAT)/6.0)^(1.5)) - + AS $_$ + SELECT CAST(($1.upvotes - $1.downvotes) AS float)/((CAST(($1.age+100000) AS FLOAT)/6.0)^(1.5)) $_$; @@ -1554,10 +1302,8 @@ ALTER FUNCTION public.rank_hot(public.comments) OWNER TO postgres; CREATE FUNCTION public.rank_hot(public.submissions) RETURNS double precision LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT 1000000.0*CAST(($1.upvotes - $1.downvotes) AS float)/((CAST(($1.age+5000) AS FLOAT)/100.0)^(1.5)) - + AS $_$ + SELECT 1000000.0*CAST(($1.upvotes - $1.downvotes) AS float)/((CAST(($1.age+5000) AS FLOAT)/100.0)^(1.5)) $_$; @@ -1569,24 +1315,15 @@ ALTER FUNCTION public.rank_hot(public.submissions) OWNER TO postgres; CREATE FUNCTION public.recent_subscriptions(public.boards) RETURNS bigint LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - select count(*) - - from subscriptions - - left join users - - on subscriptions.user_id=users.id - - where subscriptions.board_id=$1.id - - and subscriptions.is_active=true - - and subscriptions.created_utc > CAST( EXTRACT( EPOCH FROM CURRENT_TIMESTAMP) AS int) - 60*60*24 - - and users.is_banned=0 - + AS $_$ + select count(*) + from subscriptions + left join users + on subscriptions.user_id=users.id + where subscriptions.board_id=$1.id + and subscriptions.is_active=true + and subscriptions.created_utc > CAST( EXTRACT( EPOCH FROM CURRENT_TIMESTAMP) AS int) - 60*60*24 + and users.is_banned=0 $_$; @@ -1598,16 +1335,11 @@ ALTER FUNCTION public.recent_subscriptions(public.boards) OWNER TO postgres; CREATE FUNCTION public.referral_count(public.users) RETURNS bigint LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT COUNT(*) - - FROM USERS - - WHERE users.is_banned=0 - - AND users.referred_by=$1.id - + AS $_$ + SELECT COUNT(*) + FROM USERS + WHERE users.is_banned=0 + AND users.referred_by=$1.id $_$; @@ -1619,20 +1351,13 @@ ALTER FUNCTION public.referral_count(public.users) OWNER TO postgres; CREATE FUNCTION public.report_count(public.submissions) RETURNS bigint LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT COUNT(*) - - FROM reports - - JOIN users ON reports.user_id=users.id - - WHERE post_id=$1.id - - AND users.is_banned=0 - - and reports.created_utc >= $1.edited_utc - + AS $_$ + SELECT COUNT(*) + FROM reports + JOIN users ON reports.user_id=users.id + WHERE post_id=$1.id + AND users.is_banned=0 + and reports.created_utc >= $1.edited_utc $_$; @@ -1644,10 +1369,8 @@ ALTER FUNCTION public.report_count(public.submissions) OWNER TO postgres; CREATE FUNCTION public.score(public.comments) RETURNS integer LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT ($1.upvotes - $1.downvotes) - + AS $_$ + SELECT ($1.upvotes - $1.downvotes) $_$; @@ -1659,10 +1382,8 @@ ALTER FUNCTION public.score(public.comments) OWNER TO postgres; CREATE FUNCTION public.score(public.submissions) RETURNS integer LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT ($1.upvotes - $1.downvotes) - + AS $_$ + SELECT ($1.upvotes - $1.downvotes) $_$; @@ -1700,18 +1421,12 @@ ALTER TABLE public.images OWNER TO postgres; CREATE FUNCTION public.splash(text) RETURNS SETOF public.images LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - SELECT * - - FROM images - - WHERE state=$1 - - ORDER BY random() - - LIMIT 1 - + AS $_$ + SELECT * + FROM images + WHERE state=$1 + ORDER BY random() + LIMIT 1 $_$; @@ -1723,144 +1438,75 @@ ALTER FUNCTION public.splash(text) OWNER TO postgres; CREATE FUNCTION public.subscriber_count(public.boards) RETURNS bigint LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - - - select - - case - - when $1.is_private=false - - then - - ( - - ( - - select count(*) - - from subscriptions - - left join users - - on subscriptions.user_id=users.id - - where subscriptions.board_id=$1.id - - and subscriptions.is_active=true - - and users.is_deleted=false and (users.is_banned=0 or users.unban_utc>0) - - )-( - - select count(distinct s1.id) - - from - - ( - - select * - - from subscriptions - - where board_id=$1.id - - and is_active=true - - ) as s1 - - join (select * from users where is_banned=0 or unban_utc>0) as u1 - - on u1.id=s1.user_id - - join (select * from alts) as a - - on (a.user1=s1.user_id or a.user2=s1.user_id) - - join ( - - select * - - from subscriptions - - where board_id=$1.id - - and is_active=true - - ) as s2 - - on ((a.user1=s2.user_id or a.user2=s2.user_id) and s2.id != s1.id) - - join (select * from users where is_banned=0 or unban_utc>0) as u2 - - on u2.id=s2.user_id - - where s1.id is not null - - and s2.id is not null - - ) - - ) - - when $1.is_private=true - - then - - ( - - ( - - select count(*) - - from subscriptions - - left join users - - on subscriptions.user_id=users.id - - left join ( - - select * from contributors - - where contributors.board_id=$1.id - - )as contribs - - on contribs.user_id=users.id - - left join ( - - select * from mods - - where mods.board_id=$1.id - - and accepted=true - - )as m - - on m.user_id=users.id - - where subscriptions.board_id=$1.id - - and subscriptions.is_active=true - - and users.is_deleted=false and (users.is_banned=0 or users.unban_utc>0) - - and (contribs.user_id is not null or m.id is not null) - - ) - - ) - - end - - - - - + AS $_$ + + select + case + when $1.is_private=false + then + ( + ( + select count(*) + from subscriptions + left join users + on subscriptions.user_id=users.id + where subscriptions.board_id=$1.id + and subscriptions.is_active=true + and users.is_deleted=false and (users.is_banned=0 or users.unban_utc>0) + )-( + select count(distinct s1.id) + from + ( + select * + from subscriptions + where board_id=$1.id + and is_active=true + ) as s1 + join (select * from users where is_banned=0 or unban_utc>0) as u1 + on u1.id=s1.user_id + join (select * from alts) as a + on (a.user1=s1.user_id or a.user2=s1.user_id) + join ( + select * + from subscriptions + where board_id=$1.id + and is_active=true + ) as s2 + on ((a.user1=s2.user_id or a.user2=s2.user_id) and s2.id != s1.id) + join (select * from users where is_banned=0 or unban_utc>0) as u2 + on u2.id=s2.user_id + where s1.id is not null + and s2.id is not null + ) + ) + when $1.is_private=true + then + ( + ( + select count(*) + from subscriptions + left join users + on subscriptions.user_id=users.id + left join ( + select * from contributors + where contributors.board_id=$1.id + )as contribs + on contribs.user_id=users.id + left join ( + select * from mods + where mods.board_id=$1.id + and accepted=true + )as m + on m.user_id=users.id + where subscriptions.board_id=$1.id + and subscriptions.is_active=true + and users.is_deleted=false and (users.is_banned=0 or users.unban_utc>0) + and (contribs.user_id is not null or m.id is not null) + ) + ) + end + + $_$; @@ -1872,24 +1518,15 @@ ALTER FUNCTION public.subscriber_count(public.boards) OWNER TO postgres; CREATE FUNCTION public.trending_rank(public.boards) RETURNS double precision LANGUAGE sql IMMUTABLE STRICT - AS $_$ - - - -select - - case - - when $1.subscriber_count<=10 then 0 - - when $1.age < 60*60*24*5 then 0 - - when $1.recent_subscriptions<=5 then 0 - - when $1.subscriber_count>=9 then ((cast($1.subscriber_count as float))^(1/3) + cast($1.recent_subscriptions as float)) / cast($1.subscriber_count + 10000 as float) - - end - + AS $_$ + +select + case + when $1.subscriber_count<=10 then 0 + when $1.age < 60*60*24*5 then 0 + when $1.recent_subscriptions<=5 then 0 + when $1.subscriber_count>=9 then ((cast($1.subscriber_count as float))^(1/3) + cast($1.recent_subscriptions as float)) / cast($1.subscriber_count + 10000 as float) + end $_$; @@ -1901,114 +1538,60 @@ ALTER FUNCTION public.trending_rank(public.boards) OWNER TO postgres; CREATE FUNCTION public.ups(public.comments) RETURNS bigint LANGUAGE sql - AS $_$ - -select ( - -( - - SELECT count(*) - - from ( - - select * from commentvotes - - where comment_id=$1.id - - and vote_type=1 - - and user_id not in - - ( - - select user_id - - from bans - - where board_id=$1.original_board_id - - and is_active=true - - ) - - ) as v1 - - join (select * from users where users.is_banned=0 or users.unban_utc>0) as u0 - - on u0.id=v1.user_id - -)-( - - SELECT count(distinct v1.id) - - from ( - - select * from commentvotes - - where comment_id=$1.id - - and vote_type=1 - - and user_id not in - - ( - - select user_id - - from bans - - where board_id=$1.original_board_id - - and is_active=true - - ) - - ) as v1 - - join (select * from users where is_banned=0 or users.unban_utc>0) as u1 - - on u1.id=v1.user_id - - join (select * from alts) as a - - on (a.user1=v1.user_id or a.user2=v1.user_id) - - join ( - - select * from commentvotes - - where comment_id=$1.id - - and vote_type=1 - - and user_id not in - - ( - - select user_id - - from bans - - where board_id=$1.original_board_id - - and is_active=true - - ) - - ) as v2 - - on ((a.user1=v2.user_id or a.user2=v2.user_id) and v2.id != v1.id) - - join (select * from users where is_banned=0 or users.unban_utc>0) as u2 - - on u2.id=v2.user_id - - where v1.id is not null - - and v2.id is not null - -)) - + AS $_$ +select ( +( + SELECT count(*) + from ( + select * from commentvotes + where comment_id=$1.id + and vote_type=1 + and user_id not in + ( + select user_id + from bans + where board_id=$1.original_board_id + and is_active=true + ) + ) as v1 + join (select * from users where users.is_banned=0 or users.unban_utc>0) as u0 + on u0.id=v1.user_id +)-( + SELECT count(distinct v1.id) + from ( + select * from commentvotes + where comment_id=$1.id + and vote_type=1 + and user_id not in + ( + select user_id + from bans + where board_id=$1.original_board_id + and is_active=true + ) + ) as v1 + join (select * from users where is_banned=0 or users.unban_utc>0) as u1 + on u1.id=v1.user_id + join (select * from alts) as a + on (a.user1=v1.user_id or a.user2=v1.user_id) + join ( + select * from commentvotes + where comment_id=$1.id + and vote_type=1 + and user_id not in + ( + select user_id + from bans + where board_id=$1.original_board_id + and is_active=true + ) + ) as v2 + on ((a.user1=v2.user_id or a.user2=v2.user_id) and v2.id != v1.id) + join (select * from users where is_banned=0 or users.unban_utc>0) as u2 + on u2.id=v2.user_id + where v1.id is not null + and v2.id is not null +)) $_$; @@ -2020,114 +1603,60 @@ ALTER FUNCTION public.ups(public.comments) OWNER TO postgres; CREATE FUNCTION public.ups(public.submissions) RETURNS bigint LANGUAGE sql - AS $_$ - -select ( - -( - - SELECT count(*) - - from ( - - select * from votes - - where submission_id=$1.id - - and vote_type=1 - - and user_id not in - - ( - - select user_id - - from bans - - where board_id=$1.board_id - - and is_active=true - - ) - - ) as v1 - - join (select * from users where users.is_banned=0 or users.unban_utc>0) as u0 - - on u0.id=v1.user_id - -)-( - - SELECT count(distinct v1.id) - - from ( - - select * from votes - - where submission_id=$1.id - - and vote_type=1 - - and user_id not in - - ( - - select user_id - - from bans - - where board_id=$1.board_id - - and is_active=true - - ) - - ) as v1 - - join (select * from users where is_banned=0 or users.unban_utc>0) as u1 - - on u1.id=v1.user_id - - join (select * from alts) as a - - on (a.user1=v1.user_id or a.user2=v1.user_id) - - join ( - - select * from votes - - where submission_id=$1.id - - and vote_type=1 - - and user_id not in - - ( - - select user_id - - from bans - - where board_id=$1.board_id - - and is_active=true - - ) - - ) as v2 - - on ((a.user1=v2.user_id or a.user2=v2.user_id) and v2.id != v1.id) - - join (select * from users where is_banned=0 or users.unban_utc>0) as u2 - - on u2.id=v2.user_id - - where v1.id is not null - - and v2.id is not null - -)) - + AS $_$ +select ( +( + SELECT count(*) + from ( + select * from votes + where submission_id=$1.id + and vote_type=1 + and user_id not in + ( + select user_id + from bans + where board_id=$1.board_id + and is_active=true + ) + ) as v1 + join (select * from users where users.is_banned=0 or users.unban_utc>0) as u0 + on u0.id=v1.user_id +)-( + SELECT count(distinct v1.id) + from ( + select * from votes + where submission_id=$1.id + and vote_type=1 + and user_id not in + ( + select user_id + from bans + where board_id=$1.board_id + and is_active=true + ) + ) as v1 + join (select * from users where is_banned=0 or users.unban_utc>0) as u1 + on u1.id=v1.user_id + join (select * from alts) as a + on (a.user1=v1.user_id or a.user2=v1.user_id) + join ( + select * from votes + where submission_id=$1.id + and vote_type=1 + and user_id not in + ( + select user_id + from bans + where board_id=$1.board_id + and is_active=true + ) + ) as v2 + on ((a.user1=v2.user_id or a.user2=v2.user_id) and v2.id != v1.id) + join (select * from users where is_banned=0 or users.unban_utc>0) as u2 + on u2.id=v2.user_id + where v1.id is not null + and v2.id is not null +)) $_$; @@ -2139,72 +1668,39 @@ ALTER FUNCTION public.ups(public.submissions) OWNER TO postgres; CREATE FUNCTION public.ups_test(public.submissions) RETURNS bigint LANGUAGE sql IMMUTABLE STRICT - AS $_$ - -select ( - -( - - SELECT count(*) - - from ( - - select * from votes - - where submission_id=$1.id - - and vote_type=1 - - ) as v1 - - join (select * from users where users.is_banned=0) as u0 - - on u0.id=v1.user_id - -)-( - - SELECT count(distinct v1.id) - - from ( - - select * from votes - - where submission_id=$1.id - - and vote_type=1 - - ) as v1 - - join (select * from users where is_banned=0) as u1 - - on u1.id=v1.user_id - - join (select * from alts) as a - - on (a.user1=v1.user_id or a.user2=v1.user_id) - - join ( - - select * from votes - - where submission_id=$1.id - - and vote_type=1 - - ) as v2 - - on ((a.user1=v2.id or a.user2=v2.id) and v2.id != v1.id) - - join (select * from users where is_banned=0) as u2 - - on u2.id=v2.user_id - - where v1.id is not null - - and v2.id is not null - -)) - + AS $_$ +select ( +( + SELECT count(*) + from ( + select * from votes + where submission_id=$1.id + and vote_type=1 + ) as v1 + join (select * from users where users.is_banned=0) as u0 + on u0.id=v1.user_id +)-( + SELECT count(distinct v1.id) + from ( + select * from votes + where submission_id=$1.id + and vote_type=1 + ) as v1 + join (select * from users where is_banned=0) as u1 + on u1.id=v1.user_id + join (select * from alts) as a + on (a.user1=v1.user_id or a.user2=v1.user_id) + join ( + select * from votes + where submission_id=$1.id + and vote_type=1 + ) as v2 + on ((a.user1=v2.id or a.user2=v2.id) and v2.id != v1.id) + join (select * from users where is_banned=0) as u2 + on u2.id=v2.user_id + where v1.id is not null + and v2.id is not null +)) $_$; @@ -3295,7 +2791,6 @@ ALTER SEQUENCE public.messages_id_seq OWNED BY public.messages.id; CREATE TABLE public.modactions ( id integer NOT NULL, user_id integer, - board_id integer, target_user_id integer, target_submission_id integer, target_comment_id integer, @@ -5377,7 +4872,7 @@ CREATE INDEX domains_domain_trgm_idx ON public.domains USING gin (domain public. -- --- Name: flag_user_idx; Type: INDEX; Schema: public; Owdeleted_utcres +-- Name: flag_user_idx; Type: INDEX; Schema: public; Owner: postgres -- CREATE INDEX flag_user_idx ON public.flags USING btree (user_id); @@ -5467,13 +4962,6 @@ CREATE INDEX mod_user_index ON public.mods USING btree (user_id); CREATE INDEX modaction_action_idx ON public.modactions USING btree (kind); --- --- Name: modaction_board_idx; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX modaction_board_idx ON public.modactions USING btree (board_id); - - -- -- Name: modaction_cid_idx; Type: INDEX; Schema: public; Owner: postgres -- @@ -5628,34 +5116,6 @@ CREATE INDEX sub_user_index ON public.subscriptions USING btree (user_id); CREATE INDEX subimssion_binary_group_idx ON public.submissions USING btree (is_banned, deleted_utc, over_18); --- --- Name: submission_activity_disputed_idx; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX submission_activity_disputed_idx ON public.submissions USING btree (score_disputed DESC, board_id); - - --- --- Name: submission_activity_hot_idx; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX submission_activity_hot_idx ON public.submissions USING btree (score_hot DESC, board_id); - - --- --- Name: submission_activity_sort_idx; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX submission_activity_sort_idx ON public.submissions USING btree (score_activity DESC, board_id); - - --- --- Name: submission_activity_top_idx; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX submission_activity_top_idx ON public.submissions USING btree (score_top DESC, board_id); - - -- -- Name: submission_aux_url_idx; Type: INDEX; Schema: public; Owner: postgres -- @@ -5677,13 +5137,6 @@ CREATE INDEX submission_aux_url_trgm_idx ON public.submissions_aux USING gin (ur CREATE INDEX submission_best_only_idx ON public.submissions USING btree (score_best DESC); --- --- Name: submission_best_sort_idx; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX submission_best_sort_idx ON public.submissions USING btree (score_best DESC, board_id); - - -- -- Name: submission_disputed_sort_idx; Type: INDEX; Schema: public; Owner: postgres -- @@ -5754,13 +5207,6 @@ CREATE INDEX submission_pinned_idx ON public.submissions USING btree (is_pinned) CREATE INDEX submission_purge_idx ON public.submissions USING btree (purged_utc); --- --- Name: submission_time_board_idx; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX submission_time_board_idx ON public.submissions USING btree (created_utc, board_id) WHERE (created_utc > 1590859918); - - -- -- Name: submissions_author_index; Type: INDEX; Schema: public; Owner: postgres -- @@ -5782,13 +5228,6 @@ CREATE INDEX submissions_aux_id_idx ON public.submissions_aux USING btree (id); CREATE INDEX submissions_aux_title_idx ON public.submissions_aux USING btree (title); --- --- Name: submissions_board_index; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX submissions_board_index ON public.submissions USING btree (board_id); - - -- -- Name: submissions_created_utc_desc_idx; Type: INDEX; Schema: public; Owner: postgres -- @@ -6094,14 +5533,6 @@ ALTER TABLE ONLY public.subcategories ADD CONSTRAINT subcategories_cat_id_fkey FOREIGN KEY (cat_id) REFERENCES public.categories(id); --- --- Name: submissions submissions_board_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY public.submissions - ADD CONSTRAINT submissions_board_id_fkey FOREIGN KEY (board_id) REFERENCES public.boards(id); - - -- -- Name: submissions submissions_original_board_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres --