diff --git a/drama/classes/__init__.py b/drama/classes/__init__.py index e0cd59c2c..974be51ef 100644 --- a/drama/classes/__init__.py +++ b/drama/classes/__init__.py @@ -11,7 +11,7 @@ from .votes import * from .images import * from .domains import * from .subscriptions import * -from .ips import * +from .agents import * from .titles import * from .lolwtf import * from .mod_logs import * \ No newline at end of file diff --git a/drama/classes/ips.py b/drama/classes/agents.py similarity index 100% rename from drama/classes/ips.py rename to drama/classes/agents.py diff --git a/drama/classes/user.py b/drama/classes/user.py index 471607b1f..2279a17d6 100644 --- a/drama/classes/user.py +++ b/drama/classes/user.py @@ -50,7 +50,6 @@ class User(Base, Stndrd, Age_times): newtab = Column(Boolean, default=False) newtabexternal = Column(Boolean, default=True) oldreddit = Column(Boolean, default=False) - creation_ip = Column(String) submissions = relationship( "Submission", lazy="dynamic", @@ -65,7 +64,6 @@ class User(Base, Stndrd, Age_times): bio = Column(String, default="") bio_html = Column(String, default="") badges = relationship("Badge", lazy="dynamic", backref="user") - real_id = Column(String) notifications = relationship( "Notification", lazy="dynamic") @@ -78,48 +76,22 @@ class User(Base, Stndrd, Age_times): is_banned = Column(Integer, default=None) unban_utc = Column(Integer, default=None) ban_reason = Column(String, default="") - feed_nonce = Column(Integer, default=0) login_nonce = Column(Integer, default=0) - title_id = Column(Integer, ForeignKey("titles.id")) title = relationship("Title", lazy="joined") - has_banner = Column(Boolean, default=False) reserved = Column(String(256)) - is_nsfw = Column(Boolean, default=False) - profile_nonce = Column(Integer, default=0) dramacoins = Column(Integer, default=0) - banner_nonce = Column(Integer, default=0) - last_siege_utc = Column(Integer, default=0) mfa_secret = deferred(Column(String(16))) - hide_offensive = Column(Boolean, default=False) - hide_bot = Column(Boolean, default=False) is_private = Column(Boolean, default=False) - read_announcement_utc = Column(Integer, default=0) - filter_nsfw = Column(Boolean, default=False) stored_subscriber_count = Column(Integer, default=0) defaultsortingcomments = Column(String, default="top") defaultsorting = Column(String, default="hot") defaulttime = Column(String, default="all") - coin_balance = Column(Integer, default=0) - premium_expires_utc = Column(Integer, default=0) - negative_balance_cents = Column(Integer, default=0) is_nofollow = Column(Boolean, default=False) custom_filter_list = Column(String(1000), default="") discord_id = Column(String(64)) - creation_region = Column(String(2)) ban_evade = Column(Integer, default=0) - - profile_upload_ip = deferred(Column(String(255))) - banner_upload_ip = deferred(Column(String(255))) - profile_upload_region = deferred(Column(String(2))) - banner_upload_region = deferred(Column(String(2))) - - # stuff to support name changes - profile_set_utc = deferred(Column(Integer, default=0)) - banner_set_utc = deferred(Column(Integer, default=0)) original_username = deferred(Column(String(255))) - name_changed_utc = deferred(Column(Integer, default=0)) - subscriptions = relationship("Subscription") following = relationship("Follow", primaryjoin="Follow.user_id==User.id") @@ -140,7 +112,6 @@ class User(Base, Stndrd, Age_times): # properties defined as SQL server-side functions referral_count = deferred(Column(Integer, server_default=FetchedValue())) - follower_count = deferred(Column(Integer, server_default=FetchedValue())) def __init__(self, **kwargs): @@ -297,11 +268,6 @@ class User(Base, Stndrd, Age_times): def verifyPass(self, password): return check_password_hash(self.passhash, password) - @property - def feedkey(self): - - return generate_hash(f"{self.username}{self.id}{self.feed_nonce}{self.created_utc}") - @property def formkey(self): @@ -491,8 +457,6 @@ class User(Base, Stndrd, Age_times): def set_profile(self, file): self.del_profile() - self.profile_nonce += 1 - imageurl = upload_file(name=f"profile.gif", file=file, resize=(100, 100)) if imageurl: self.profileurl = imageurl @@ -504,12 +468,9 @@ class User(Base, Stndrd, Age_times): def set_banner(self, file): self.del_banner() - self.banner_nonce += 1 - imageurl = upload_file(name=f"banner.gif", file=file) if imageurl: self.bannerurl = imageurl - self.has_banner = True self.banner_upload_ip = request.remote_addr self.banner_set_utc = int(time.time()) self.banner_upload_region = request.headers.get("cf-ipcountry") @@ -522,16 +483,13 @@ class User(Base, Stndrd, Age_times): def del_banner(self): - self.has_banner = False + self.bannerurl = None g.db.add(self) @property def banner_url(self): - if self.has_banner: - if self.bannerurl: - return self.bannerurl - else: - return f"https://s3.eu-central-1.amazonaws.com/i.drama.ga/uid/{self.base36id}/banner-{self.banner_nonce}.png" + if self.bannerurl: + return self.bannerurl else: return "/assets/images/default_bg.png" @@ -617,7 +575,7 @@ class User(Base, Stndrd, Age_times): self.unban_utc = ban_time else: - if self.has_banner: + if self.bannerurl: self.del_banner() if self.profileurl: self.del_profile() @@ -637,8 +595,8 @@ class User(Base, Stndrd, Age_times): # Takes care of all functions needed for account reinstatement. - self.is_banned = None - self.unban_utc = None + self.is_banned = 0 + self.unban_utc = 0 g.db.add(self) diff --git a/drama/routes/settings.py b/drama/routes/settings.py index 697ee08ec..8030f8e28 100644 --- a/drama/routes/settings.py +++ b/drama/routes/settings.py @@ -56,10 +56,6 @@ def settings_profile_post(v): updated = True v.hide_bot = request.values.get("hide_bot", None) == 'true' - if request.values.get("filter_nsfw", v.filter_nsfw) != v.filter_nsfw: - updated = True - v.filter_nsfw = not request.values.get("filter_nsfw", None) == 'true' - if request.values.get("private", v.is_private) != v.is_private: updated = True v.is_private = request.values.get("private", None) == 'true' diff --git a/drama/routes/users.py b/drama/routes/users.py index d8143c9be..89111ce97 100644 --- a/drama/routes/users.py +++ b/drama/routes/users.py @@ -49,7 +49,7 @@ def leaderboard(v): def leaderboard(): users = g.db.query(User).options(lazyload('*')) users1= sorted(users, key=lambda x: x.dramacoins, reverse=True)[:25] - users2= sorted(users, key=lambda x: x.follower_count, reverse=True)[:10] + users2= sorted(users, key=lambda x: x.stored_subscriber_count, reverse=True)[:10] return users1, users2 @app.get("/@/css") @@ -446,7 +446,7 @@ def follow_user(username, v): g.db.add(new_follow) g.db.flush() - target.stored_subscriber_count=target.follower_count + target.stored_subscriber_count=target.stored_subscriber_count g.db.add(target) g.db.commit() diff --git a/drama/templates/leaderboard.html b/drama/templates/leaderboard.html index 97a890378..547849b92 100644 --- a/drama/templates/leaderboard.html +++ b/drama/templates/leaderboard.html @@ -43,7 +43,7 @@ {{users2.index(user)+1}} {{user.username}} - {{user.follower_count}} + {{user.stored_subscriber_count}} {% endfor %} diff --git a/drama/templates/settings_profile.html b/drama/templates/settings_profile.html index e476119b1..2e632480a 100644 --- a/drama/templates/settings_profile.html +++ b/drama/templates/settings_profile.html @@ -158,7 +158,7 @@
- {% if v.has_banner %} + {% if v.bannerurl %}
diff --git a/drama/templates/userpage.html b/drama/templates/userpage.html index 07fe7b632..448d1e89e 100644 --- a/drama/templates/userpage.html +++ b/drama/templates/userpage.html @@ -23,10 +23,10 @@ - + - + @@ -34,8 +34,8 @@ - - + + {% endblock %} @@ -117,7 +117,7 @@ {% if u.customtitle %}

{{u.customtitle | safe}}

{% endif %}
- {{u.dramacoins}} Dramacoins   {% if u.follower_count >=1 and not u.is_nofollow %}{{u.follower_count}} follower{{'s' if u.follower_count != 1 else ''}}   {% endif %}joined {{u.created_date}} + {{u.dramacoins}} Dramacoins   {% if u.stored_subscriber_count >=1 and not u.is_nofollow %}{{u.stored_subscriber_count}} follower{{'s' if u.stored_subscriber_count != 1 else ''}}   {% endif %}joined {{u.created_date}}
{% if u.bio_html %}

@@ -296,7 +296,7 @@
 				{% endif %}
 				{% if u.customtitle %}

{{u.customtitle | safe}}

{% endif %}
- {{u.dramacoins}} Dramacoins  {% if u.follower_count >=1 and not u.is_nofollow %}{{u.follower_count}} follower{{'s' if u.follower_count != 1 else ''}}   {% endif %}
joined {{u.created_date}} + {{u.dramacoins}} Dramacoins  {% if u.stored_subscriber_count >=1 and not u.is_nofollow %}{{u.stored_subscriber_count}} follower{{'s' if u.stored_subscriber_count != 1 else ''}}   {% endif %}
joined {{u.created_date}}
{% if u.bio_html %}

{{u.bio_html | safe}}

diff --git a/schema.sql b/schema.sql index 5acc7c69e..966867629 100644 --- a/schema.sql +++ b/schema.sql @@ -355,7 +355,7 @@ DROP FUNCTION public.rank_activity(public.submissions); DROP FUNCTION public.mod_count(public.users); DROP FUNCTION public.is_deleted(public.notifications); DROP FUNCTION public.is_banned(public.notifications); -DROP FUNCTION public.follower_count(public.users); +DROP FUNCTION public.stored_subscriber_count(public.users); DROP FUNCTION public.flag_count(public.submissions); DROP FUNCTION public.flag_count(public.comments); DROP FUNCTION public.energy(public.users); @@ -474,8 +474,10 @@ 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 + $_$; @@ -537,8 +539,10 @@ 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 + $_$; @@ -650,8 +654,10 @@ 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 + $_$; @@ -663,10 +669,14 @@ ALTER FUNCTION public.age(public.users) 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 + $_$; @@ -692,10 +702,14 @@ 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 + $_$; @@ -732,17 +746,28 @@ 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 + + ) + $_$; @@ -772,9 +797,12 @@ 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 + $_$; @@ -946,16 +974,26 @@ 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 + + ) + $_$; @@ -967,12 +1005,18 @@ 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 + $_$; @@ -984,63 +1028,105 @@ 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 + $_$; ALTER FUNCTION public.flag_count(public.submissions) OWNER TO postgres; -- --- Name: follower_count(public.users); Type: FUNCTION; Schema: public; Owner: postgres +-- Name: stored_subscriber_count(public.users); Type: FUNCTION; Schema: public; Owner: postgres -- -CREATE FUNCTION public.follower_count(public.users) RETURNS bigint +CREATE FUNCTION public.stored_subscriber_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 + + ) + + + + + + + + ) + $_$; -ALTER FUNCTION public.follower_count(public.users) OWNER TO postgres; +ALTER FUNCTION public.stored_subscriber_count(public.users) OWNER TO postgres; -- -- Name: is_banned(public.notifications); Type: FUNCTION; Schema: public; Owner: postgres @@ -1048,9 +1134,12 @@ 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 + $_$; @@ -1062,9 +1151,12 @@ 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 + $_$; @@ -1087,8 +1179,10 @@ 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)) + $_$; @@ -1100,8 +1194,10 @@ 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)) + $_$; @@ -1113,8 +1209,10 @@ 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(($1.upvotes * $1.downvotes) AS float)) + AS $_$ + + SELECT SQRT(CAST(($1.upvotes * $1.downvotes) AS float)) + $_$; @@ -1126,8 +1224,10 @@ 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)) + $_$; @@ -1139,8 +1239,10 @@ 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)) + $_$; @@ -1152,8 +1254,10 @@ 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)) + $_$; @@ -1165,11 +1269,16 @@ ALTER FUNCTION public.rank_hot(public.submissions) 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 + $_$; @@ -1181,13 +1290,20 @@ 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 + $_$; @@ -1199,8 +1315,10 @@ 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) + $_$; @@ -1212,8 +1330,10 @@ 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) + $_$; @@ -1251,12 +1371,18 @@ 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 + $_$; @@ -1422,39 +1548,72 @@ 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 + +)) + $_$;