redundant

remotes/1693045480750635534/spooky-22
Aevann1 2021-11-06 17:52:48 +02:00
parent 18ea3b164f
commit 9e449dd8b0
24 changed files with 284 additions and 289 deletions

View File

@ -58,6 +58,8 @@ services:
postgres:
image: postgres:12.3
# command: ["postgres", "-c", "log_statement=all"]
# uncomment this if u wanna output all SQL queries to the console
volumes:
- "./schema.sql:/docker-entrypoint-initdb.d/00-schema.sql"
- "./seed-db.sql:/docker-entrypoint-initdb.d/10-seed-db.sql"

View File

@ -39,7 +39,7 @@ class OauthApp(Base):
@lazy
def idlist(self, page=1):
posts = g.db.query(Submission.id).options(lazyload('*')).filter_by(app_id=self.id)
posts = g.db.query(Submission.id).filter_by(app_id=self.id)
posts=posts.order_by(Submission.created_utc.desc())
@ -50,7 +50,7 @@ class OauthApp(Base):
@lazy
def comments_idlist(self, page=1):
posts = g.db.query(Comment.id).options(lazyload('*')).filter_by(app_id=self.id)
posts = g.db.query(Comment.id).filter_by(app_id=self.id)
posts=posts.order_by(Comment.created_utc.desc())

View File

@ -67,12 +67,12 @@ class Comment(Base):
@property
@lazy
def flags(self):
return g.db.query(CommentFlag).options(lazyload('*')).filter_by(comment_id=self.id)
return g.db.query(CommentFlag).filter_by(comment_id=self.id)
@lazy
def poll_voted(self, v):
if v:
vote = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id, comment_id=self.id).first()
vote = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=self.id).first()
if vote: return vote.vote_type
else: return None
else: return None
@ -173,7 +173,7 @@ class Comment(Base):
if self.level == 1: return self.post
else: return g.db.query(Comment).options(lazyload('*')).get(self.parent_comment_id)
else: return g.db.query(Comment).get(self.parent_comment_id)
@property
@lazy

View File

@ -76,12 +76,12 @@ class Submission(Base):
@property
@lazy
def flags(self):
return g.db.query(Flag).options(lazyload('*')).filter_by(post_id=self.id)
return g.db.query(Flag).filter_by(post_id=self.id)
@property
@lazy
def options(self):
return g.db.query(Comment).options(lazyload('*')).filter_by(parent_submission = self.id, author_id = AUTOPOLLER_ACCOUNT, level=1)
return g.db.query(Comment).filter_by(parent_submission = self.id, author_id = AUTOPOLLER_ACCOUNT, level=1)
def total_poll_voted(self, v):
if v:

View File

@ -115,6 +115,7 @@ class User(Base):
referred_by = Column(Integer, ForeignKey("users.id"))
badges = relationship("Badge", viewonly=True)
subscriptions = relationship("Subscription", viewonly=True)
following = relationship("Follow", primaryjoin="Follow.user_id==User.id", viewonly=True)
followers = relationship("Follow", primaryjoin="Follow.target_id==User.id", viewonly=True)
@ -139,7 +140,7 @@ class User(Base):
@property
@lazy
def notifications(self):
return g.db.query(Notification).options(lazyload('*')).filter_by(user_id=self.id)
return g.db.query(Notification).filter_by(user_id=self.id)
@property
@lazy
@ -153,7 +154,7 @@ class User(Base):
return_value = list(AWARDS2.values())
user_awards = g.db.query(AwardRelationship).options(lazyload('*')).filter_by(user_id=self.id)
user_awards = g.db.query(AwardRelationship).filter_by(user_id=self.id)
for val in return_value: val['owned'] = user_awards.filter_by(kind=val['kind'], submission_id=None, comment_id=None).count()
@ -166,7 +167,7 @@ class User(Base):
def has_block(self, target):
return g.db.query(UserBlock).options(lazyload('*')).filter_by(
return g.db.query(UserBlock).filter_by(
user_id=self.id, target_id=target.id).first()
@property
@ -176,7 +177,7 @@ class User(Base):
def any_block_exists(self, other):
return g.db.query(UserBlock).options(lazyload('*')).filter(
return g.db.query(UserBlock).filter(
or_(and_(UserBlock.user_id == self.id, UserBlock.target_id == other.id), and_(
UserBlock.user_id == other.id, UserBlock.target_id == self.id))).first()
@ -209,7 +210,7 @@ class User(Base):
if self.shadowbanned and not (v and (v.admin_level >= 3 or v.id == self.id)):
return []
posts = g.db.query(Submission.id).options(lazyload('*')).filter_by(author_id=self.id, is_pinned=False)
posts = g.db.query(Submission.id).filter_by(author_id=self.id, is_pinned=False)
if not (v and (v.admin_level >= 3 or v.id == self.id)):
posts = posts.filter_by(deleted_utc=0, is_banned=False, private=False)
@ -260,7 +261,7 @@ class User(Base):
@lazy
def banned_by(self):
if not self.is_suspended: return None
return g.db.query(User).options(lazyload('*')).filter_by(id=self.is_banned).first()
return g.db.query(User).filter_by(id=self.is_banned).first()
def has_badge(self, badgedef_id):
return g.db.query(Badge).filter_by(user_id=self.id, badge_id=badgedef_id).first()
@ -325,11 +326,11 @@ class User(Base):
awards = {}
posts_idlist = [x[0] for x in g.db.query(Submission.id).options(lazyload('*')).filter_by(author_id=self.id).all()]
comments_idlist = [x[0] for x in g.db.query(Comment.id).options(lazyload('*')).filter_by(author_id=self.id).all()]
posts_idlist = [x[0] for x in g.db.query(Submission.id).filter_by(author_id=self.id).all()]
comments_idlist = [x[0] for x in g.db.query(Comment.id).filter_by(author_id=self.id).all()]
post_awards = g.db.query(AwardRelationship).options(lazyload('*')).filter(AwardRelationship.submission_id.in_(posts_idlist)).all()
comment_awards = g.db.query(AwardRelationship).options(lazyload('*')).filter(AwardRelationship.comment_id.in_(comments_idlist)).all()
post_awards = g.db.query(AwardRelationship).filter(AwardRelationship.submission_id.in_(posts_idlist)).all()
comment_awards = g.db.query(AwardRelationship).filter(AwardRelationship.comment_id.in_(comments_idlist)).all()
total_awards = post_awards + comment_awards
@ -345,19 +346,19 @@ class User(Base):
@property
@lazy
def notifications_count(self):
return g.db.query(Notification.id).options(lazyload('*')).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0).count()
return g.db.query(Notification.id).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0).count()
@property
@lazy
def post_notifications_count(self):
return g.db.query(Notification.id).options(lazyload('*')).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.author_id == AUTOJANNY_ACCOUNT).count()
return g.db.query(Notification.id).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.author_id == AUTOJANNY_ACCOUNT).count()
@property
@lazy
def alts(self):
subq = g.db.query(Alt).options(lazyload('*')).filter(
subq = g.db.query(Alt).filter(
or_(
Alt.user1 == self.id,
Alt.user2 == self.id
@ -367,7 +368,7 @@ class User(Base):
data = g.db.query(
User,
aliased(Alt, alias=subq)
).options(lazyload('*')).join(
).join(
subq,
or_(
subq.c.user1 == User.id,
@ -388,7 +389,7 @@ class User(Base):
def has_follower(self, user):
return g.db.query(Follow).options(lazyload('*')).filter_by(target_id=self.id, user_id=user.id).first()
return g.db.query(Follow).filter_by(target_id=self.id, user_id=user.id).first()
@property
@lazy
@ -479,27 +480,27 @@ class User(Base):
@property
@lazy
def applications(self):
return g.db.query(OauthApp).options(lazyload('*')).filter_by(author_id=self.id).order_by(OauthApp.id.asc()).all()
return g.db.query(OauthApp).filter_by(author_id=self.id).order_by(OauthApp.id.asc()).all()
@lazy
def subscribed_idlist(self, page=1):
posts = g.db.query(Subscription.submission_id).options(lazyload('*')).filter_by(user_id=self.id).all()
posts = g.db.query(Subscription.submission_id).filter_by(user_id=self.id).all()
return [x[0] for x in posts]
@lazy
def saved_idlist(self, page=1):
posts = g.db.query(Submission.id).options(lazyload('*')).filter_by(is_banned=False, deleted_utc=0)
posts = g.db.query(Submission.id).filter_by(is_banned=False, deleted_utc=0)
saved = [x[0] for x in g.db.query(SaveRelationship.submission_id).options(lazyload('*')).filter(SaveRelationship.user_id == self.id).all()]
saved = [x[0] for x in g.db.query(SaveRelationship.submission_id).filter(SaveRelationship.user_id == self.id).all()]
posts = posts.filter(Submission.id.in_(saved))
if self.admin_level == 0:
blocking = [x[0] for x in g.db.query(
UserBlock.target_id).options(lazyload('*')).filter_by(
UserBlock.target_id).filter_by(
user_id=self.id).all()]
blocked = [x[0] for x in g.db.query(
UserBlock.user_id).options(lazyload('*')).filter_by(
UserBlock.user_id).filter_by(
target_id=self.id).all()]
posts = posts.filter(
@ -514,16 +515,16 @@ class User(Base):
@lazy
def saved_comment_idlist(self):
try: saved = [x[0] for x in g.db.query(SaveRelationship.comment_id).options(lazyload('*')).filter(SaveRelationship.user_id == self.id).all()]
try: saved = [x[0] for x in g.db.query(SaveRelationship.comment_id).filter(SaveRelationship.user_id == self.id).all()]
except: return []
comments = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.id.in_(saved))
comments = g.db.query(Comment.id).filter(Comment.id.in_(saved))
if self.admin_level == 0:
blocking = [x[0] for x in g.db.query(
UserBlock.target_id).options(lazyload('*')).filter_by(
UserBlock.target_id).filter_by(
user_id=self.id).all()]
blocked = [x[0] for x in g.db.query(
UserBlock.user_id).options(lazyload('*')).filter_by(
UserBlock.user_id).filter_by(
target_id=self.id).all()]
comments = comments.filter(

View File

@ -127,7 +127,7 @@ def send_admin(vid, text):
g.db.add(new_comment)
g.db.flush()
admins = g.db.query(User).options(lazyload('*')).filter(User.admin_level > 0).all()
admins = g.db.query(User).filter(User.admin_level > 0).all()
for admin in admins:
notif = Notification(comment_id=new_comment.id, user_id=admin.id)
g.db.add(notif)

View File

@ -27,7 +27,7 @@ def filter_comment_html(html_text):
domain_list.add(new_domain)
bans = [x for x in g.db.query(BannedDomain).options(lazyload('*')).filter(BannedDomain.domain.in_(list(domain_list))).all()]
bans = [x for x in g.db.query(BannedDomain).filter(BannedDomain.domain.in_(list(domain_list))).all()]
if bans: return bans
else: return []

View File

@ -9,7 +9,7 @@ def get_user(username, v=None, graceful=False):
user = g.db.query(
User
).options(lazyload('*')).filter(
).filter(
or_(
User.username.ilike(username),
User.original_username.ilike(username)
@ -23,7 +23,7 @@ def get_user(username, v=None, graceful=False):
return None
if v:
block = g.db.query(UserBlock).options(lazyload('*')).filter(
block = g.db.query(UserBlock).filter(
or_(
and_(
UserBlock.user_id == v.id,
@ -42,16 +42,16 @@ def get_user(username, v=None, graceful=False):
def get_account(id, v=None):
user = g.db.query(User).options(lazyload('*')).filter_by(id = id).first()
user = g.db.query(User).filter_by(id = id).first()
if not user:
try: id = int(str(id), 36)
except: abort(404)
user = g.db.query(User).options(lazyload('*')).filter_by(id = id).first()
user = g.db.query(User).filter_by(id = id).first()
if not user: abort(404)
if v:
block = g.db.query(UserBlock).options(lazyload('*')).filter(
block = g.db.query(UserBlock).filter(
or_(
and_(
UserBlock.user_id == v.id,
@ -72,7 +72,7 @@ def get_account(id, v=None):
def get_post(i, v=None, graceful=False):
if v:
vt = g.db.query(Vote).options(lazyload('*')).filter_by(
vt = g.db.query(Vote).filter_by(
user_id=v.id, submission_id=i).subquery()
blocking = v.blocking.subquery()
@ -80,7 +80,7 @@ def get_post(i, v=None, graceful=False):
Submission,
vt.c.vote_type,
blocking.c.id,
).options(lazyload('*'))
)
items=items.filter(Submission.id == i
).join(
@ -103,7 +103,7 @@ def get_post(i, v=None, graceful=False):
else:
items = g.db.query(
Submission
).options(lazyload('*')).filter(Submission.id == i).first()
).filter(Submission.id == i).first()
if not items and not graceful:
abort(404)
x=items
@ -119,7 +119,7 @@ def get_posts(pids, v=None):
pids=tuple(pids)
if v:
vt = g.db.query(Vote).options(lazyload('*')).filter(
vt = g.db.query(Vote).filter(
Vote.submission_id.in_(pids),
Vote.user_id==v.id
).subquery()
@ -132,7 +132,7 @@ def get_posts(pids, v=None):
vt.c.vote_type,
blocking.c.id,
blocked.c.id,
).options(lazyload('*')).filter(
).filter(
Submission.id.in_(pids)
).join(
vt, vt.c.submission_id==Submission.id, isouter=True
@ -152,7 +152,7 @@ def get_posts(pids, v=None):
output[i].is_blocking = query[i][2] or 0
output[i].is_blocked = query[i][3] or 0
else:
output = g.db.query(Submission,).options(lazyload('*')).filter(Submission.id.in_(pids)).all()
output = g.db.query(Submission,).filter(Submission.id.in_(pids)).all()
return sorted(output, key=lambda x: pids.index(x.id))
@ -160,11 +160,11 @@ def get_comment(i, v=None, graceful=False):
if v:
comment=g.db.query(Comment).options(lazyload('*')).filter(Comment.id == i).first()
comment=g.db.query(Comment).filter(Comment.id == i).first()
if not comment and not graceful: abort(404)
block = g.db.query(UserBlock).options(lazyload('*')).filter(
block = g.db.query(UserBlock).filter(
or_(
and_(
UserBlock.user_id == v.id,
@ -176,14 +176,14 @@ def get_comment(i, v=None, graceful=False):
)
).first()
vts = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id)
vt = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id).first()
vts = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id)
vt = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).first()
comment.is_blocking = block and block.user_id == v.id
comment.is_blocked = block and block.target_id == v.id
comment.voted = vt.vote_type if vt else 0
else:
comment = g.db.query(Comment).options(lazyload('*')).filter(Comment.id == i).first()
comment = g.db.query(Comment).filter(Comment.id == i).first()
if not comment and not graceful:abort(404)
return comment
@ -196,7 +196,7 @@ def get_comments(cids, v=None, load_parent=False):
cids=tuple(cids)
if v:
votes = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id).subquery()
votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery()
blocking = v.blocking.subquery()
@ -207,7 +207,7 @@ def get_comments(cids, v=None, load_parent=False):
votes.c.vote_type,
blocking.c.id,
blocked.c.id,
).options(lazyload('*')).filter(Comment.id.in_(cids))
).filter(Comment.id.in_(cids))
if not (v and v.shadowbanned) and not (v and v.admin_level == 6):
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
@ -235,7 +235,7 @@ def get_comments(cids, v=None, load_parent=False):
output.append(comment)
else:
output = g.db.query(Comment).options(lazyload('*')).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.id.in_(cids)).all()
output = g.db.query(Comment).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.id.in_(cids)).all()
if load_parent:
parents = [x.parent_comment_id for x in output if x.parent_comment_id]
@ -259,7 +259,7 @@ def get_domain(s):
domain_list = tuple(list(domain_list))
doms = [x for x in g.db.query(BannedDomain).options(lazyload('*')).filter(BannedDomain.domain.in_(domain_list)).all()]
doms = [x for x in g.db.query(BannedDomain).filter(BannedDomain.domain.in_(domain_list)).all()]
if not doms:
return None

View File

@ -10,7 +10,7 @@ def get_logged_in_user():
if not token: return None
try:
client = g.db.query(ClientAuth).options(lazyload('*')).filter(ClientAuth.access_token == token).first()
client = g.db.query(ClientAuth).filter(ClientAuth.access_token == token).first()
x = (client.user, client) if client else (None, None)
except: x = (None, None)
@ -21,7 +21,7 @@ def get_logged_in_user():
nonce = session.get("login_nonce", 0)
if not uid: x= (None, None)
try:
if g.db: v = g.db.query(User).options(lazyload('*')).filter_by(id=uid).first()
if g.db: v = g.db.query(User).filter_by(id=uid).first()
else: v = None
except: v = None
@ -44,7 +44,7 @@ def check_ban_evade(v):
v.ban(reason="permaban evasion")
send_notification(v.id, "Your account has been permanently suspended for the following reason:\n\n> permaban evasion")
for post in g.db.query(Submission).options(lazyload('*')).filter_by(author_id=v.id).all():
for post in g.db.query(Submission).filter_by(author_id=v.id).all():
if post.is_banned:
continue
@ -60,7 +60,7 @@ def check_ban_evade(v):
)
g.db.add(ma)
for comment in g.db.query(Comment).options(lazyload('*')).filter_by(author_id=v.id).all():
for comment in g.db.query(Comment).filter_by(author_id=v.id).all():
if comment.is_banned:
continue

View File

@ -66,7 +66,7 @@ def activate(v):
if not validate_hash(f"{email}+{id}+{timestamp}", token):
abort(403)
user = g.db.query(User).options(lazyload('*')).filter_by(id=id).first()
user = g.db.query(User).filter_by(id=id).first()
if not user:
abort(404)

View File

@ -20,19 +20,11 @@ from files.helpers.discord import add_role
SITE_NAME = environ.get("SITE_NAME", "").strip()
@app.get("/fix")
@admin_level_required(6)
def fix(v):
for u in g.db.query(User).options(lazyload('*')).all():
u.post_count = g.db.query(Submission.id).options(lazyload('*')).filter_by(author_id=u.id, is_banned=False, deleted_utc=0).count()
g.db.add(u)
g.db.commit()
return 'sex'
@app.get("/truescore")
@admin_level_required(6)
def truescore(v):
users = g.db.query(User).options(lazyload('*')).order_by(User.truecoins.desc()).limit(25).all()
users = g.db.query(User).order_by(User.truecoins.desc()).limit(25).all()
return render_template("truescore.html", v=v, users=users)
@ -44,14 +36,14 @@ def revert_actions(v, username):
user = get_user(username)
if not user: abort(404)
items = g.db.query(Submission).options(lazyload('*')).filter_by(removed_by=user.id).all() + g.db.query(Comment).options(lazyload('*')).filter_by(removed_by=user.id).all()
items = g.db.query(Submission).filter_by(removed_by=user.id).all() + g.db.query(Comment).filter_by(removed_by=user.id).all()
for item in items:
item.is_banned = False
item.removed_by = None
g.db.add(item)
users = g.db.query(User).options(lazyload('*')).filter_by(is_banned=user.id).all()
users = g.db.query(User).filter_by(is_banned=user.id).all()
for user in users:
user.is_banned = 0
user.unban_utc = 0
@ -179,8 +171,8 @@ def remove_fake_admin(v, username):
@admin_level_required(6)
def monthly(v):
if 'pcm' in request.host or (SITE_NAME == 'Drama' and v.id in [1,28,995,2513]) or ('rama' not in request.host and 'pcm' not in request.host):
thing = g.db.query(AwardRelationship).options(lazyload('*')).order_by(AwardRelationship.id.desc()).first().id
for u in g.db.query(User).options(lazyload('*')).filter(User.patron > 0).all():
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id
for u in g.db.query(User).filter(User.patron > 0).all():
if u.patron == 1: procoins = 2000
elif u.patron == 2: procoins = 5000
elif u.patron == 3: procoins = 10000
@ -234,7 +226,7 @@ def post_rules(v):
@auth_required
def shadowbanned(v):
if not (v and v.admin_level == 6): abort(404)
users = [x for x in g.db.query(User).options(lazyload('*')).filter(User.shadowbanned != None).all()]
users = [x for x in g.db.query(User).filter(User.shadowbanned != None).all()]
return render_template("banned.html", v=v, users=users)
@ -242,7 +234,7 @@ def shadowbanned(v):
@auth_required
def agendaposters(v):
if not (v and v.admin_level == 6): abort(404)
users = [x for x in g.db.query(User).options(lazyload('*')).filter_by(agendaposter = True).all()]
users = [x for x in g.db.query(User).filter_by(agendaposter = True).all()]
return render_template("banned.html", v=v, users=users)
@ -253,7 +245,7 @@ def image_posts_listing(v):
try: page = int(request.values.get('page', 1))
except: page = 1
posts = g.db.query(Submission).options(lazyload('*')).order_by(Submission.id.desc())
posts = g.db.query(Submission).order_by(Submission.id.desc())
firstrange = 25 * (page - 1)
secondrange = firstrange+26
@ -270,7 +262,7 @@ def reported_posts(v):
page = max(1, int(request.values.get("page", 1)))
posts = g.db.query(Submission).options(lazyload('*')).filter_by(
posts = g.db.query(Submission).filter_by(
is_approved=0,
is_banned=False
).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26)
@ -292,7 +284,7 @@ def reported_comments(v):
page = max(1, int(request.values.get("page", 1)))
posts = g.db.query(Comment
).options(lazyload('*')).filter_by(
).filter_by(
is_approved=0,
is_banned=False
).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all()
@ -335,7 +327,7 @@ def disablesignups(v):
@admin_level_required(4)
def badge_grant_get(v):
badge_types = g.db.query(BadgeDef).options(lazyload('*')).all()
badge_types = g.db.query(BadgeDef).all()
errors = {"already_owned": "That user already has that badge.",
"no_user": "That user doesn't exist."
@ -365,7 +357,7 @@ def badge_grant_post(v):
except: abort(400)
if user.has_badge(badge_id):
g.db.delete(g.db.query(Badge).options(lazyload('*')).filter_by(badge_id=badge_id, user_id=user.id))
g.db.delete(g.db.query(Badge).filter_by(badge_id=badge_id, user_id=user.id))
g.db.commit()
return redirect("/admin/badge_grant")
@ -403,7 +395,7 @@ def users_list(v):
page = int(request.values.get("page", 1))
users = g.db.query(User).options(lazyload('*')).filter_by(is_banned=0
users = g.db.query(User).filter_by(is_banned=0
).order_by(User.created_utc.desc()
).offset(25 * (page - 1)).limit(26)
@ -436,35 +428,35 @@ def alt_votes_get(v):
u2 = get_user(u2)
u1_post_ups = g.db.query(
Vote.submission_id).options(lazyload('*')).filter_by(
Vote.submission_id).filter_by(
user_id=u1.id,
vote_type=1).all()
u1_post_downs = g.db.query(
Vote.submission_id).options(lazyload('*')).filter_by(
Vote.submission_id).filter_by(
user_id=u1.id,
vote_type=-1).all()
u1_comment_ups = g.db.query(
CommentVote.comment_id).options(lazyload('*')).filter_by(
CommentVote.comment_id).filter_by(
user_id=u1.id,
vote_type=1).all()
u1_comment_downs = g.db.query(
CommentVote.comment_id).options(lazyload('*')).filter_by(
CommentVote.comment_id).filter_by(
user_id=u1.id,
vote_type=-1).all()
u2_post_ups = g.db.query(
Vote.submission_id).options(lazyload('*')).filter_by(
Vote.submission_id).filter_by(
user_id=u2.id,
vote_type=1).all()
u2_post_downs = g.db.query(
Vote.submission_id).options(lazyload('*')).filter_by(
Vote.submission_id).filter_by(
user_id=u2.id,
vote_type=-1).all()
u2_comment_ups = g.db.query(
CommentVote.comment_id).options(lazyload('*')).filter_by(
CommentVote.comment_id).filter_by(
user_id=u2.id,
vote_type=1).all()
u2_comment_downs = g.db.query(
CommentVote.comment_id).options(lazyload('*')).filter_by(
CommentVote.comment_id).filter_by(
user_id=u2.id,
vote_type=-1).all()
@ -546,7 +538,7 @@ def admin_link_accounts(v):
g.db.add(new_alt)
g.db.commit()
return redirect(f"/admin/alt_votes?u1={g.db.query(User).get(u1).username}&u2={g.db.query(User).options(lazyload('*')).get(u2).username}")
return redirect(f"/admin/alt_votes?u1={g.db.query(User).get(u1).username}&u2={g.db.query(User).get(u2).username}")
@app.get("/admin/removed")
@ -555,7 +547,7 @@ def admin_removed(v):
page = int(request.values.get("page", 1))
ids = g.db.query(Submission.id).options(lazyload('*')).join(User, User.id == Submission.author_id).filter(or_(Submission.is_banned==True, User.shadowbanned != None)).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26).all()
ids = g.db.query(Submission.id).join(User, User.id == Submission.author_id).filter(or_(Submission.is_banned==True, User.shadowbanned != None)).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26).all()
ids=[x[0] for x in ids]
@ -578,7 +570,7 @@ def admin_removed(v):
@admin_level_required(6)
@validate_formkey
def agendaposter(user_id, v):
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
user = g.db.query(User).filter_by(id=user_id).first()
expiry = request.values.get("days", 0)
if expiry:
@ -631,7 +623,7 @@ def agendaposter(user_id, v):
@admin_level_required(6)
@validate_formkey
def shadowban(user_id, v):
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
user = g.db.query(User).filter_by(id=user_id).first()
if user.admin_level != 0: abort(403)
user.shadowbanned = v.username
g.db.add(user)
@ -657,7 +649,7 @@ def shadowban(user_id, v):
@admin_level_required(6)
@validate_formkey
def unshadowban(user_id, v):
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
user = g.db.query(User).filter_by(id=user_id).first()
if user.admin_level != 0: abort(403)
user.shadowbanned = None
g.db.add(user)
@ -682,7 +674,7 @@ def unshadowban(user_id, v):
@admin_level_required(6)
@validate_formkey
def verify(user_id, v):
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
user = g.db.query(User).filter_by(id=user_id).first()
user.verified = "Verified"
g.db.add(user)
@ -701,7 +693,7 @@ def verify(user_id, v):
@admin_level_required(6)
@validate_formkey
def unverify(user_id, v):
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
user = g.db.query(User).filter_by(id=user_id).first()
user.verified = None
g.db.add(user)
@ -722,7 +714,7 @@ def unverify(user_id, v):
@validate_formkey
def admin_title_change(user_id, v):
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
user = g.db.query(User).filter_by(id=user_id).first()
if user.admin_level != 0: abort(403)
@ -731,7 +723,7 @@ def admin_title_change(user_id, v):
user.customtitleplain=new_name
new_name = sanitize(new_name)
user=g.db.query(User).with_for_update().options(lazyload('*')).filter_by(id=user.id).first()
user=g.db.query(User).with_for_update().filter_by(id=user.id).first()
user.customtitle=new_name
if request.values.get("locked"): user.flairchanged = time.time() + 2629746
g.db.add(user)
@ -756,7 +748,7 @@ def admin_title_change(user_id, v):
@validate_formkey
def ban_user(user_id, v):
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
user = g.db.query(User).filter_by(id=user_id).first()
if user.admin_level >= v.admin_level: abort(403)
@ -831,7 +823,7 @@ def ban_user(user_id, v):
@validate_formkey
def unban_user(user_id, v):
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
user = g.db.query(User).filter_by(id=user_id).first()
if not user:
abort(400)
@ -871,7 +863,7 @@ def unban_user(user_id, v):
@validate_formkey
def ban_post(post_id, v):
post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first()
post = g.db.query(Submission).filter_by(id=post_id).first()
if not post:
abort(400)
@ -909,7 +901,7 @@ def ban_post(post_id, v):
@validate_formkey
def unban_post(post_id, v):
post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first()
post = g.db.query(Submission).filter_by(id=post_id).first()
if not post:
abort(400)
@ -942,7 +934,7 @@ def unban_post(post_id, v):
@validate_formkey
def api_distinguish_post(post_id, v):
post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first()
post = g.db.query(Submission).filter_by(id=post_id).first()
if not post:
abort(404)
@ -966,7 +958,7 @@ def api_distinguish_post(post_id, v):
@admin_level_required(3)
def api_sticky_post(post_id, v):
post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first()
post = g.db.query(Submission).filter_by(id=post_id).first()
if post:
if post.stickied:
if post.stickied.startswith("t:"): abort(403)
@ -992,7 +984,7 @@ def api_sticky_post(post_id, v):
@admin_level_required(1)
def api_ban_comment(c_id, v):
comment = g.db.query(Comment).options(lazyload('*')).filter_by(id=c_id).first()
comment = g.db.query(Comment).filter_by(id=c_id).first()
if not comment:
abort(404)
@ -1016,7 +1008,7 @@ def api_ban_comment(c_id, v):
@admin_level_required(1)
def api_unban_comment(c_id, v):
comment = g.db.query(Comment).options(lazyload('*')).filter_by(id=c_id).first()
comment = g.db.query(Comment).filter_by(id=c_id).first()
if not comment:
abort(404)
g.db.add(comment)
@ -1074,7 +1066,7 @@ def admin_dump_cache(v):
@admin_level_required(4)
def admin_banned_domains(v):
banned_domains = g.db.query(BannedDomain).options(lazyload('*')).all()
banned_domains = g.db.query(BannedDomain).all()
return render_template("admin/banned_domains.html", v=v, banned_domains=banned_domains)
@app.post("/admin/banned_domains")
@ -1088,7 +1080,7 @@ def admin_toggle_ban_domain(v):
reason=request.values.get("reason", "").strip()
d = g.db.query(BannedDomain).options(lazyload('*')).filter_by(domain=domain).first()
d = g.db.query(BannedDomain).filter_by(domain=domain).first()
if d:
g.db.delete(d)
ma = ModAction(
@ -1121,14 +1113,14 @@ def admin_nuke_user(v):
user=get_user(request.values.get("user"))
for post in g.db.query(Submission).options(lazyload('*')).filter_by(author_id=user.id).all():
for post in g.db.query(Submission).filter_by(author_id=user.id).all():
if post.is_banned:
continue
post.is_banned=True
g.db.add(post)
for comment in g.db.query(Comment).options(lazyload('*')).filter_by(author_id=user.id).all():
for comment in g.db.query(Comment).filter_by(author_id=user.id).all():
if comment.is_banned:
continue
@ -1155,14 +1147,14 @@ def admin_nunuke_user(v):
user=get_user(request.values.get("user"))
for post in g.db.query(Submission).options(lazyload('*')).filter_by(author_id=user.id).all():
for post in g.db.query(Submission).filter_by(author_id=user.id).all():
if not post.is_banned:
continue
post.is_banned=False
g.db.add(post)
for comment in g.db.query(Comment).options(lazyload('*')).filter_by(author_id=user.id).all():
for comment in g.db.query(Comment).filter_by(author_id=user.id).all():
if not comment.is_banned:
continue

View File

@ -167,7 +167,7 @@ def shop(v):
},
}
for useraward in g.db.query(AwardRelationship).options(lazyload('*')).filter(AwardRelationship.user_id == v.id, AwardRelationship.submission_id == None, AwardRelationship.comment_id == None).all():
for useraward in g.db.query(AwardRelationship).filter(AwardRelationship.user_id == v.id, AwardRelationship.submission_id == None, AwardRelationship.comment_id == None).all():
if useraward.kind in AWARDS: AWARDS[useraward.kind]["owned"] += 1
if v.patron == 1: discount = 0.90
@ -183,7 +183,7 @@ def shop(v):
for val in AWARDS.values():
val["price"] = int(val["price"]*discount)
sales = g.db.query(Vote.id).count() + g.db.query(CommentVote.id).count() - g.db.query(func.sum(User.coins).options(lazyload('*'))).scalar()
sales = g.db.query(Vote.id).count() + g.db.query(CommentVote.id).count() - g.db.query(func.sum(User.coins)).scalar()
return render_template("shop.html", awards=list(AWARDS.values()), v=v, sales=sales)
@ -346,7 +346,7 @@ def buy(v, award):
g.db.add(v)
g.db.flush()
thing = g.db.query(AwardRelationship).options(lazyload('*')).order_by(AwardRelationship.id.desc()).first().id
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id
thing += 1
award = AwardRelationship(id=thing, user_id=v.id, kind=award)
@ -369,7 +369,7 @@ def award_post(pid, v):
if kind not in AWARDS:
return {"error": "That award doesn't exist."}, 404
post_award = g.db.query(AwardRelationship).options(lazyload('*')).filter(
post_award = g.db.query(AwardRelationship).filter(
and_(
AwardRelationship.kind == kind,
AwardRelationship.user_id == v.id,
@ -381,12 +381,12 @@ def award_post(pid, v):
if not post_award:
return {"error": "You don't have that award."}, 404
post = g.db.query(Submission).options(lazyload('*')).filter_by(id=pid).first()
post = g.db.query(Submission).filter_by(id=pid).first()
if not post:
return {"error": "That post doesn't exist."}, 404
existing_award = g.db.query(AwardRelationship).options(lazyload('*')).filter(
existing_award = g.db.query(AwardRelationship).filter(
and_(
AwardRelationship.submission_id == post.id,
AwardRelationship.user_id == v.id,
@ -491,7 +491,7 @@ def award_comment(cid, v):
if kind not in AWARDS:
return {"error": "That award doesn't exist."}, 404
comment_award = g.db.query(AwardRelationship).options(lazyload('*')).filter(
comment_award = g.db.query(AwardRelationship).filter(
and_(
AwardRelationship.kind == kind,
AwardRelationship.user_id == v.id,
@ -503,12 +503,12 @@ def award_comment(cid, v):
if not comment_award:
return {"error": "You don't have that award."}, 404
c = g.db.query(Comment).options(lazyload('*')).filter_by(id=cid).first()
c = g.db.query(Comment).filter_by(id=cid).first()
if not c:
return {"error": "That comment doesn't exist."}, 404
existing_award = g.db.query(AwardRelationship).options(lazyload('*')).filter(
existing_award = g.db.query(AwardRelationship).filter(
and_(
AwardRelationship.comment_id == c.id,
AwardRelationship.user_id == v.id,
@ -619,7 +619,7 @@ def admin_userawards_post(v):
notify_awards = {}
latest = g.db.query(AwardRelationship).options(lazyload('*')).order_by(AwardRelationship.id.desc()).first()
latest = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first()
thing = latest.id
for key, value in request.values.items():
@ -775,7 +775,7 @@ def items(v):
},
}
for useraward in g.db.query(AwardRelationship).options(lazyload('*')).filter(AwardRelationship.user_id == v.id, AwardRelationship.submission_id == None, AwardRelationship.comment_id == None).all(): AWARDS[useraward.kind]["owned"] += 1
for useraward in g.db.query(AwardRelationship).filter(AwardRelationship.user_id == v.id, AwardRelationship.submission_id == None, AwardRelationship.comment_id == None).all(): AWARDS[useraward.kind]["owned"] += 1
if v.patron == 1: discount = 0.10
elif v.patron == 2: discount = 0.15

View File

@ -38,7 +38,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
comment = get_comment(cid, v=v)
if v and request.values.get("read"):
notif = g.db.query(Notification).options(lazyload('*')).filter_by(comment_id=cid, user_id=v.id, read=False).first()
notif = g.db.query(Notification).filter_by(comment_id=cid, user_id=v.id, read=False).first()
if notif:
notif.read = True
g.db.add(notif)
@ -77,7 +77,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
sort=request.values.get("sort", defaultsortingcomments)
if v:
votes = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id).subquery()
votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery()
blocking = v.blocking.subquery()
@ -88,7 +88,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
votes.c.vote_type,
blocking.c.id,
blocked.c.id,
).options(lazyload('*'))
)
if not (v and v.shadowbanned) and not (v and v.admin_level == 6):
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
@ -193,7 +193,7 @@ def api_comment(v):
if ban.reason: reason += f" {ban.reason}"
return {"error": reason}, 401
existing = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == v.id,
existing = g.db.query(Comment.id).filter(Comment.author_id == v.id,
Comment.deleted_utc == 0,
Comment.parent_comment_id == parent_comment_id,
Comment.parent_submission == parent_submission,
@ -407,7 +407,7 @@ def api_comment(v):
g.db.add(c2)
longpostbot = g.db.query(User).options(lazyload('*')).filter_by(id = LONGPOSTBOT_ACCOUNT).first()
longpostbot = g.db.query(User).filter_by(id = LONGPOSTBOT_ACCOUNT).first()
longpostbot.comment_count += 1
longpostbot.coins += 1
g.db.add(longpostbot)
@ -495,7 +495,7 @@ def api_comment(v):
g.db.add(c4)
zozbot = g.db.query(User).options(lazyload('*')).filter_by(id = ZOZBOT_ACCOUNT).first()
zozbot = g.db.query(User).filter_by(id = ZOZBOT_ACCOUNT).first()
zozbot.comment_count += 3
zozbot.coins += 3
g.db.add(zozbot)
@ -514,7 +514,7 @@ def api_comment(v):
if not v.shadowbanned:
notify_users = set()
for x in g.db.query(Subscription.user_id).options(lazyload('*')).filter_by(submission_id=c.parent_submission).all(): notify_users.add(x[0])
for x in g.db.query(Subscription.user_id).filter_by(submission_id=c.parent_submission).all(): notify_users.add(x[0])
if parent.author.id != v.id: notify_users.add(parent.author.id)
@ -524,7 +524,7 @@ def api_comment(v):
for mention in mentions:
username = mention["href"].split("@")[1]
user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first()
user = g.db.query(User).filter_by(username=username).first()
if user:
if v.any_block_exists(user): continue
@ -569,7 +569,7 @@ def api_comment(v):
cache.delete_memoized(comment_idlist)
v.comment_count = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == v.id, Comment.parent_submission != None).filter_by(is_banned=False, deleted_utc=0).count()
v.comment_count = g.db.query(Comment.id).filter(Comment.author_id == v.id, Comment.parent_submission != None).filter_by(is_banned=False, deleted_utc=0).count()
g.db.add(v)
parent_post.comment_count += 1
@ -763,11 +763,11 @@ def edit_comment(cid, v):
mentions = soup.find_all("a", href=re.compile("^/@(\w+)"))
if len(mentions) > 0:
notifs = g.db.query(Notification).options(lazyload('*'))
notifs = g.db.query(Notification)
for mention in mentions:
username = mention["href"].split("@")[1]
user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first()
user = g.db.query(User).filter_by(username=username).first()
if user:
if v.any_block_exists(user): continue
@ -796,7 +796,7 @@ def edit_comment(cid, v):
@validate_formkey
def delete_comment(cid, v):
c = g.db.query(Comment).options(lazyload('*')).filter_by(id=cid).first()
c = g.db.query(Comment).filter_by(id=cid).first()
if not c: abort(404)
@ -818,7 +818,7 @@ def delete_comment(cid, v):
@validate_formkey
def undelete_comment(cid, v):
c = g.db.query(Comment).options(lazyload('*')).filter_by(id=cid).first()
c = g.db.query(Comment).filter_by(id=cid).first()
if not c:
abort(404)
@ -880,7 +880,7 @@ def save_comment(cid, v):
comment=get_comment(cid)
save=g.db.query(SaveRelationship).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id, type=2).first()
save=g.db.query(SaveRelationship).filter_by(user_id=v.id, comment_id=comment.id, type=2).first()
if not save:
new_save=SaveRelationship(user_id=v.id, comment_id=comment.id, type=2)
@ -898,7 +898,7 @@ def unsave_comment(cid, v):
comment=get_comment(cid)
save=g.db.query(SaveRelationship).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id, type=2).first()
save=g.db.query(SaveRelationship).filter_by(user_id=v.id, comment_id=comment.id, type=2).first()
if save:
g.db.delete(save)

View File

@ -97,7 +97,7 @@ def discord_redirect(v):
url=f"https://discord.com/api/guilds/{SERVER_ID}/members/{v.discord_id}"
requests.delete(url, headers=headers)
if g.db.query(User).options(lazyload('*')).filter(User.id!=v.id, User.discord_id==x["id"]).first():
if g.db.query(User).filter(User.id!=v.id, User.discord_id==x["id"]).first():
return render_template("message.html", title="Discord account already linked.", error="That Discord account is already in use by another user.", v=v)
v.discord_id=x["id"]

View File

@ -20,11 +20,11 @@ def notifications(v):
modmail = request.values.get('modmail', False)
posts = request.values.get('posts', False)
if modmail and v.admin_level == 6:
comments = g.db.query(Comment).options(lazyload('*')).filter(Comment.sentto==0).order_by(Comment.created_utc.desc()).offset(25*(page-1)).limit(26).all()
comments = g.db.query(Comment).filter(Comment.sentto==0).order_by(Comment.created_utc.desc()).offset(25*(page-1)).limit(26).all()
next_exists = (len(comments) > 25)
comments = comments[:25]
elif messages:
comments = g.db.query(Comment).options(lazyload('*')).filter(or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None).order_by(Comment.created_utc.desc(), not_(Comment.child_comments.any())).offset(25*(page-1)).limit(26).all()
comments = g.db.query(Comment).filter(or_(Comment.author_id==v.id, Comment.sentto==v.id), Comment.parent_submission == None).order_by(Comment.created_utc.desc(), not_(Comment.child_comments.any())).offset(25*(page-1)).limit(26).all()
next_exists = (len(comments) > 25)
comments = comments[:25]
elif posts:
@ -146,7 +146,7 @@ def front_all(v):
@cache.memoize(timeout=86400)
def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='', gt=None, lt=None):
posts = g.db.query(Submission.id).options(lazyload('*'))
posts = g.db.query(Submission.id)
if SITE_NAME == 'Drama' and sort == "hot":
cutoff = int(time.time()) - 86400
@ -164,10 +164,10 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
if v and v.admin_level == 0:
blocking = [x[0] for x in g.db.query(
UserBlock.target_id).options(lazyload('*')).filter_by(
UserBlock.target_id).filter_by(
user_id=v.id).all()]
blocked = [x[0] for x in g.db.query(
UserBlock.user_id).options(lazyload('*')).filter_by(
UserBlock.user_id).filter_by(
target_id=v.id).all()]
posts = posts.filter(
Submission.author_id.notin_(blocking),
@ -213,10 +213,10 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
posts = posts[:size]
pins = g.db.query(Submission.id).options(lazyload('*')).filter(Submission.stickied != None, Submission.is_banned == False)
pins = g.db.query(Submission.id).filter(Submission.stickied != None, Submission.is_banned == False)
if v and v.admin_level == 0:
blocking = [x[0] for x in g.db.query(UserBlock.target_id).options(lazyload('*')).filter_by(user_id=v.id).all()]
blocked = [x[0] for x in g.db.query(UserBlock.user_id).options(lazyload('*')).filter_by(target_id=v.id).all()]
blocking = [x[0] for x in g.db.query(UserBlock.target_id).filter_by(user_id=v.id).all()]
blocked = [x[0] for x in g.db.query(UserBlock.user_id).filter_by(target_id=v.id).all()]
pins = pins.filter(Submission.author_id.notin_(blocking), Submission.author_id.notin_(blocked))
if page == 1 and not gt and not lt: posts = pins.all() + posts
@ -255,21 +255,21 @@ def changelog(v):
@cache.memoize(timeout=86400)
def changeloglist(v=None, sort="new", page=1 ,t="all"):
posts = g.db.query(Submission.id).options(lazyload('*')).filter_by(is_banned=False, private=False,).filter(Submission.deleted_utc == 0)
posts = g.db.query(Submission.id).filter_by(is_banned=False, private=False,).filter(Submission.deleted_utc == 0)
if v and v.admin_level == 0:
blocking = [x[0] for x in g.db.query(
UserBlock.target_id).options(lazyload('*')).filter_by(
UserBlock.target_id).filter_by(
user_id=v.id).all()]
blocked = [x[0] for x in g.db.query(
UserBlock.user_id).options(lazyload('*')).filter_by(
UserBlock.user_id).filter_by(
target_id=v.id).all()]
posts = posts.filter(
Submission.author_id.notin_(blocking),
Submission.author_id.notin_(blocked)
)
admins = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.admin_level == 6).all()]
admins = [x[0] for x in g.db.query(User.id).filter(User.admin_level == 6).all()]
posts = posts.filter(Submission.title.ilike('_changelog%'), Submission.author_id.in_(admins))
if t != 'all':
@ -309,7 +309,7 @@ def changeloglist(v=None, sort="new", page=1 ,t="all"):
@auth_desired
def random_post(v):
x = g.db.query(Submission).options(lazyload('*')).filter(Submission.deleted_utc == 0, Submission.is_banned == False)
x = g.db.query(Submission).filter(Submission.deleted_utc == 0, Submission.is_banned == False)
total = x.count()
n = random.randint(1, total - 2)
@ -319,19 +319,19 @@ def random_post(v):
@cache.memoize(timeout=86400)
def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all"):
posts = g.db.query(Submission).options(lazyload('*'))
cc_idlist = [x[0] for x in g.db.query(Submission.id).options(lazyload('*')).filter(Submission.club == True).all()]
posts = g.db.query(Submission)
cc_idlist = [x[0] for x in g.db.query(Submission.id).filter(Submission.club == True).all()]
posts = posts.subquery()
comments = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.parent_submission.notin_(cc_idlist))
comments = g.db.query(Comment.id).filter(Comment.parent_submission.notin_(cc_idlist))
if v and v.admin_level <= 3:
blocking = [x[0] for x in g.db.query(
UserBlock.target_id).options(lazyload('*')).filter_by(
UserBlock.target_id).filter_by(
user_id=v.id).all()]
blocked = [x[0] for x in g.db.query(
UserBlock.user_id).options(lazyload('*')).filter_by(
UserBlock.user_id).filter_by(
target_id=v.id).all()]
comments = comments.filter(

View File

@ -31,9 +31,9 @@ def check_for_alts(current_id):
if past_id == current_id:
continue
check1 = g.db.query(Alt).options(lazyload('*')).filter_by(
check1 = g.db.query(Alt).filter_by(
user1=current_id, user2=past_id).first()
check2 = g.db.query(Alt).options(lazyload('*')).filter_by(
check2 = g.db.query(Alt).filter_by(
user1=past_id, user2=current_id).first()
if not check1 and not check2:
@ -45,7 +45,7 @@ def check_for_alts(current_id):
except BaseException:
pass
alts = g.db.query(Alt).options(lazyload('*'))
alts = g.db.query(Alt)
otheralts = alts.filter(or_(Alt.user1 == past_id, Alt.user2 == past_id, Alt.user1 == current_id, Alt.user2 == current_id)).all()
for a in otheralts:
existing = alts.filter_by(user1=a.user1, user2=past_id).first()
@ -84,7 +84,7 @@ def login_post():
if not username: abort(400)
if "@" in username:
account = g.db.query(User).options(lazyload('*')).filter(
account = g.db.query(User).filter(
User.email.ilike(username)).first()
else:
account = get_user(username, graceful=True)
@ -181,7 +181,7 @@ def sign_up_get(v):
ref = request.values.get("ref", None)
if ref:
ref_user = g.db.query(User).options(lazyload('*')).filter(User.username.ilike(ref)).first()
ref_user = g.db.query(User).filter(User.username.ilike(ref)).first()
else:
ref_user = None
@ -248,7 +248,7 @@ def sign_up_post(v):
args = {"error": error}
if request.values.get("referred_by"):
user = g.db.query(User).options(lazyload('*')).filter_by(
user = g.db.query(User).filter_by(
id=request.values.get("referred_by")).first()
if user:
args["ref"] = user.username
@ -280,7 +280,7 @@ def sign_up_post(v):
return redirect(existing_account.url)
if existing_account or (email and g.db.query(
User).options(lazyload('*')).filter(User.email.ilike(email)).first()):
User).filter(User.email.ilike(email)).first()):
return new_signup(
"An account with that username or email already exists.")
@ -308,7 +308,7 @@ def sign_up_post(v):
lazyload('*')).filter_by(id=ref_id).first()
if ref_user:
badge_types = g.db.query(BadgeDef).options(lazyload('*')).filter(BadgeDef.qualification_expr.isnot(None)).all()
badge_types = g.db.query(BadgeDef).filter(BadgeDef.qualification_expr.isnot(None)).all()
for badge in badge_types:
if eval(badge.qualification_expr, {}, {'v': ref_user}):
if not ref_user.has_badge(badge.id):
@ -320,8 +320,8 @@ def sign_up_post(v):
g.db.add(ref_user)
id_1 = g.db.query(User.id).options(lazyload('*')).filter_by(id=7).count()
users_count = g.db.query(User.id).options(lazyload('*')).count() #paranoid
id_1 = g.db.query(User.id).filter_by(id=7).count()
users_count = g.db.query(User.id).count() #paranoid
if id_1 == 0 and users_count < 7: admin_level=6
else: admin_level=0
@ -333,9 +333,9 @@ def sign_up_post(v):
email=email,
created_utc=int(time.time()),
referred_by=ref_id or None,
ban_evade = int(any([x.is_banned and not x.unban_utc for x in g.db.query(User).options(lazyload('*')).filter(User.id.in_(tuple(session.get("history", [])))).all() if x])),
agendaposter = any([x.agendaposter for x in g.db.query(User).options(lazyload('*')).filter(User.id.in_(tuple(session.get("history", [])))).all() if x]),
club_banned=any([x.club_banned for x in g.db.query(User).options(lazyload('*')).filter(User.id.in_(tuple(session.get("history", [])))).all() if x])
ban_evade = int(any([x.is_banned and not x.unban_utc for x in g.db.query(User).filter(User.id.in_(tuple(session.get("history", [])))).all() if x])),
agendaposter = any([x.agendaposter for x in g.db.query(User).filter(User.id.in_(tuple(session.get("history", [])))).all() if x]),
club_banned=any([x.club_banned for x in g.db.query(User).filter(User.id.in_(tuple(session.get("history", [])))).all() if x])
)
g.db.add(new_user)
@ -372,7 +372,7 @@ def post_forgot():
email=email.replace("_","\_")
user = g.db.query(User).options(lazyload('*')).filter(
user = g.db.query(User).filter(
User.username.ilike(username),
User.email.ilike(email)).first()
@ -381,7 +381,7 @@ def post_forgot():
email=email.split('+')[0]
email=email.replace('.','')
email=f"{email}@gmail.com"
user = g.db.query(User).options(lazyload('*')).filter(
user = g.db.query(User).filter(
User.username.ilike(username),
User.email.ilike(email)).first()
@ -415,7 +415,7 @@ def get_reset():
title="Password reset link expired",
error="That password reset link has expired.")
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
user = g.db.query(User).filter_by(id=user_id).first()
if not validate_hash(f"{user_id}+{timestamp}+forgot+{user.login_nonce}", token):
abort(400)
@ -453,7 +453,7 @@ def post_reset(v):
title="Password reset expired",
error="That password reset form has expired.")
user = g.db.query(User).options(lazyload('*')).filter_by(id=user_id).first()
user = g.db.query(User).filter_by(id=user_id).first()
if not validate_hash(f"{user_id}+{timestamp}+reset+{user.login_nonce}", token):
abort(400)

View File

@ -11,7 +11,7 @@ from sqlalchemy.orm import joinedload
@auth_required
def authorize_prompt(v):
client_id = request.values.get("client_id")
application = g.db.query(OauthApp).options(lazyload('*')).filter_by(client_id=client_id).first()
application = g.db.query(OauthApp).filter_by(client_id=client_id).first()
if not application: return {"oauth_error": "Invalid `client_id`"}, 401
return render_template("oauth.html", v=v, application=application)
@ -23,7 +23,7 @@ def authorize_prompt(v):
def authorize(v):
client_id = request.values.get("client_id")
application = g.db.query(OauthApp).options(lazyload('*')).filter_by(client_id=client_id).first()
application = g.db.query(OauthApp).filter_by(client_id=client_id).first()
if not application: return {"oauth_error": "Invalid `client_id`"}, 401
access_token = secrets.token_urlsafe(128)[:128]
new_auth = ClientAuth(oauth_client = application.id, user_id = v.id, access_token=access_token)
@ -63,11 +63,11 @@ def request_api_keys(v):
def delete_oauth_app(v, aid):
aid = int(aid)
app = g.db.query(OauthApp).options(lazyload('*')).filter_by(id=aid).first()
app = g.db.query(OauthApp).filter_by(id=aid).first()
if app.author_id != v.id: abort(403)
for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all():
for auth in g.db.query(ClientAuth).filter_by(oauth_client=app.id).all():
g.db.delete(auth)
g.db.delete(app)
@ -84,7 +84,7 @@ def delete_oauth_app(v, aid):
def edit_oauth_app(v, aid):
aid = int(aid)
app = g.db.query(OauthApp).options(lazyload('*')).filter_by(id=aid).first()
app = g.db.query(OauthApp).filter_by(id=aid).first()
if app.author_id != v.id: abort(403)
@ -105,7 +105,7 @@ def edit_oauth_app(v, aid):
@validate_formkey
def admin_app_approve(v, aid):
app = g.db.query(OauthApp).options(lazyload('*')).filter_by(id=aid).first()
app = g.db.query(OauthApp).filter_by(id=aid).first()
user = app.author
app.client_id = secrets.token_urlsafe(64)[:64]
@ -140,9 +140,9 @@ def admin_app_approve(v, aid):
@validate_formkey
def admin_app_revoke(v, aid):
app = g.db.query(OauthApp).options(lazyload('*')).filter_by(id=aid).first()
app = g.db.query(OauthApp).filter_by(id=aid).first()
if app.id:
for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
for auth in g.db.query(ClientAuth).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
send_notification(app.author.id, f"Your application `{app.app_name}` has been revoked.")
@ -166,9 +166,9 @@ def admin_app_revoke(v, aid):
@validate_formkey
def admin_app_reject(v, aid):
app = g.db.query(OauthApp).options(lazyload('*')).filter_by(id=aid).first()
app = g.db.query(OauthApp).filter_by(id=aid).first()
for auth in g.db.query(ClientAuth).options(lazyload('*')).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
for auth in g.db.query(ClientAuth).filter_by(oauth_client=app.id).all(): g.db.delete(auth)
send_notification(app.author.id, f"Your application `{app.app_name}` has been rejected.")
@ -245,7 +245,7 @@ def admin_app_id_comments(v, aid):
@admin_level_required(3)
def admin_apps_list(v):
apps = g.db.query(OauthApp).options(lazyload('*')).all()
apps = g.db.query(OauthApp).all()
return render_template("admin/apps.html", v=v, apps=apps)
@ -257,7 +257,7 @@ def reroll_oauth_tokens(aid, v):
aid = aid
a = g.db.query(OauthApp).options(lazyload('*')).filter_by(id=aid).first()
a = g.db.query(OauthApp).filter_by(id=aid).first()
if a.author_id != v.id: abort(403)

View File

@ -63,7 +63,7 @@ def publish(pid, v):
soup = BeautifulSoup(post.body_html, features="html.parser")
for mention in soup.find_all("a", href=re.compile("^/@(\w+)")):
username = mention["href"].split("@")[1]
user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first()
user = g.db.query(User).filter_by(username=username).first()
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id)
if request.host == 'rdrama.net':
@ -119,7 +119,7 @@ def post_id(pid, anything=None, v=None):
if post.club and not (v and v.paid_dues) or post.private and not (v and (v.id == post.author_id or v.admin_level == 6)): abort(403)
if v:
votes = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id).subquery()
votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery()
blocking = v.blocking.subquery()
@ -130,7 +130,7 @@ def post_id(pid, anything=None, v=None):
votes.c.vote_type,
blocking.c.id,
blocked.c.id,
).options(lazyload('*'))
)
if not (v and v.shadowbanned) and not (v and v.admin_level == 6):
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
@ -173,7 +173,7 @@ def post_id(pid, anything=None, v=None):
post.replies = [x for x in output if x.is_pinned] + [x for x in output if x.level == 1 and not x.is_pinned]
else:
comments = g.db.query(Comment).options(lazyload('*')).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.parent_submission == post.id, Comment.author_id != AUTOPOLLER_ACCOUNT)
comments = g.db.query(Comment).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.parent_submission == post.id, Comment.author_id != AUTOPOLLER_ACCOUNT)
if sort == "new":
comments = comments.order_by(Comment.created_utc.desc())
@ -325,7 +325,7 @@ def edit_post(pid, v):
soup = BeautifulSoup(body_html, features="html.parser")
for mention in soup.find_all("a", href=re.compile("^/@(\w+)")):
username = mention["href"].split("@")[1]
user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first()
user = g.db.query(User).filter_by(username=username).first()
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id)
message = f"@{v.username} has mentioned you: http://{site}{p.permalink}"
@ -336,7 +336,7 @@ def edit_post(pid, v):
if 'carp' in f'{body_html}{title}'.lower() and 995 not in notify_users: notify_users.add(995)
for x in notify_users:
existing = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message, Comment.notifiedto == x).first()
existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message, Comment.notifiedto == x).first()
if not existing: send_notification(x, message)
@ -391,11 +391,11 @@ def thumbnail_thread(pid):
db = db_session()
post = db.query(Submission).options(lazyload('*')).filter_by(id=pid).first()
post = db.query(Submission).filter_by(id=pid).first()
if not post:
time.sleep(5)
post = db.query(Submission).options(lazyload('*')).filter_by(id=pid).first()
post = db.query(Submission).filter_by(id=pid).first()
fetch_url=post.url
@ -540,7 +540,7 @@ def submit_post(v):
fragment=parsed_url.fragment)
url = urlunparse(new_url)
repost = g.db.query(Submission).options(lazyload('*')).filter(
repost = g.db.query(Submission).filter(
Submission.url.ilike(url),
Submission.deleted_utc == 0,
Submission.is_banned == False
@ -596,7 +596,7 @@ def submit_post(v):
marregex = list(re.finditer("^(:!?m\w+:\s*)+$", body))
if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403
dup = g.db.query(Submission).options(lazyload('*')).filter(
dup = g.db.query(Submission).filter(
Submission.author_id == v.id,
Submission.deleted_utc == 0,
Submission.title == title,
@ -777,7 +777,7 @@ def submit_post(v):
soup = BeautifulSoup(body_html, features="html.parser")
for mention in soup.find_all("a", href=re.compile("^/@(\w+)")):
username = mention["href"].split("@")[1]
user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first()
user = g.db.query(User).filter_by(username=username).first()
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id)
if request.host == 'rdrama.net':
@ -915,7 +915,7 @@ def submit_post(v):
g.db.add(c)
snappy = g.db.query(User).options(lazyload('*')).filter_by(id = SNAPPY_ACCOUNT).first()
snappy = g.db.query(User).filter_by(id = SNAPPY_ACCOUNT).first()
snappy.comment_count += 1
snappy.coins += 1
g.db.add(snappy)
@ -927,7 +927,7 @@ def submit_post(v):
g.db.add(n)
g.db.flush()
v.post_count = g.db.query(Submission.id).options(lazyload('*')).filter_by(author_id=v.id, is_banned=False, deleted_utc=0).count()
v.post_count = g.db.query(Submission.id).filter_by(author_id=v.id, is_banned=False, deleted_utc=0).count()
g.db.add(v)
cache.delete_memoized(frontlist)
@ -986,7 +986,7 @@ def undelete_post_pid(pid, v):
@validate_formkey
def toggle_comment_nsfw(cid, v):
comment = g.db.query(Comment).options(lazyload('*')).filter_by(id=cid).first()
comment = g.db.query(Comment).filter_by(id=cid).first()
if not comment.author_id == v.id and not v.admin_level >= 3: abort(403)
comment.over_18 = not comment.over_18
g.db.add(comment)
@ -1031,7 +1031,7 @@ def save_post(pid, v):
post=get_post(pid)
save = g.db.query(SaveRelationship).options(lazyload('*')).filter_by(user_id=v.id, submission_id=post.id, type=1).first()
save = g.db.query(SaveRelationship).filter_by(user_id=v.id, submission_id=post.id, type=1).first()
if not save:
new_save=SaveRelationship(user_id=v.id, submission_id=post.id, type=1)
@ -1048,7 +1048,7 @@ def unsave_post(pid, v):
post=get_post(pid)
save = g.db.query(SaveRelationship).options(lazyload('*')).filter_by(user_id=v.id, submission_id=post.id, type=1).first()
save = g.db.query(SaveRelationship).filter_by(user_id=v.id, submission_id=post.id, type=1).first()
if save:
g.db.delete(save)
@ -1060,7 +1060,7 @@ def unsave_post(pid, v):
@auth_required
def api_pin_post(post_id, v):
post = g.db.query(Submission).options(lazyload('*')).filter_by(id=post_id).first()
post = g.db.query(Submission).filter_by(id=post_id).first()
if post:
post.is_pinned = not post.is_pinned
g.db.add(post)

View File

@ -12,7 +12,7 @@ def api_flag_post(pid, v):
post = get_post(pid)
if v and not v.shadowbanned:
existing = g.db.query(Flag.id).options(lazyload('*')).filter_by(user_id=v.id, post_id=post.id).first()
existing = g.db.query(Flag.id).filter_by(user_id=v.id, post_id=post.id).first()
if existing: return "", 409
@ -44,7 +44,7 @@ def api_flag_comment(cid, v):
comment = get_comment(cid)
if v and not v.shadowbanned:
existing = g.db.query(CommentFlag.id).options(lazyload('*')).filter_by(
existing = g.db.query(CommentFlag.id).filter_by(
user_id=v.id, comment_id=comment.id).first()
if existing: return "", 409
@ -77,9 +77,9 @@ def remove_report(report_fn, v):
return {"error": "go outside"}, 403
if report_fn.startswith('c'):
report = g.db.query(CommentFlag).options(lazyload('*')).filter_by(id=int(report_fn.lstrip('c'))).first()
report = g.db.query(CommentFlag).filter_by(id=int(report_fn.lstrip('c'))).first()
elif report_fn.startswith('p'):
report = g.db.query(Flag).options(lazyload('*')).filter_by(id=int(report_fn.lstrip('p'))).first()
report = g.db.query(Flag).filter_by(id=int(report_fn.lstrip('p'))).first()
else:
return {"error": "Invalid report ID"}, 400

View File

@ -57,7 +57,7 @@ def searchposts(v):
posts = g.db.query(Submission.id).options(lazyload('*'))
posts = g.db.query(Submission.id)
if not (v and v.admin_level == 6): posts = posts.filter(Submission.private == False)
@ -100,10 +100,10 @@ def searchposts(v):
pass
elif v:
blocking = [x[0] for x in g.db.query(
UserBlock.target_id).options(lazyload('*')).filter_by(
UserBlock.target_id).filter_by(
user_id=v.id).all()]
blocked = [x[0] for x in g.db.query(
UserBlock.user_id).options(lazyload('*')).filter_by(
UserBlock.user_id).filter_by(
target_id=v.id).all()]
posts = posts.filter(
@ -195,7 +195,7 @@ def searchcomments(v):
comments = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.parent_submission != None)
comments = g.db.query(Comment.id).filter(Comment.parent_submission != None)
if 'q' in criteria:
words=criteria['q'].split()
@ -272,7 +272,7 @@ def searchusers(v):
term=term.replace('\\','')
term=term.replace('_','\_')
users=g.db.query(User).options(lazyload('*')).filter(User.username.ilike(f'%{term}%'))
users=g.db.query(User).filter(User.username.ilike(f'%{term}%'))
users=users.order_by(User.username.ilike(term).desc(), User.stored_subscriber_count.desc())

View File

@ -217,14 +217,14 @@ def settings_profile_post(v):
soup = BeautifulSoup(friends_html, features="html.parser")
for mention in soup.find_all("a", href=re.compile("^/@(\w+)")):
username = mention["href"].split("@")[1]
user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first()
user = g.db.query(User).filter_by(username=username).first()
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id)
if request.host == 'rdrama.net' and 'aevann' in friends_html.lower() and 1 not in notify_users: notify_users.add(1)
for x in notify_users:
message = f"@{v.username} has added you to their friends list!"
existing = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message, Comment.notifiedto == x).first()
existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message, Comment.notifiedto == x).first()
if not existing: send_notification(x, message)
v.friends = friends[:500]
@ -262,14 +262,14 @@ def settings_profile_post(v):
soup = BeautifulSoup(enemies_html, features="html.parser")
for mention in soup.find_all("a", href=re.compile("^/@(\w+)")):
username = mention["href"].split("@")[1]
user = g.db.query(User).options(lazyload('*')).filter_by(username=username).first()
user = g.db.query(User).filter_by(username=username).first()
if user and not v.any_block_exists(user) and user.id != v.id: notify_users.add(user.id)
if request.host == 'rdrama.net' and 'aevann' in enemies_html.lower() and 1 not in notify_users: notify_users.add(1)
for x in notify_users:
message = f"@{v.username} has added you to their enemies list!"
existing = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message, Comment.notifiedto == x).first()
existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message, Comment.notifiedto == x).first()
if not existing: send_notification(x, message)
v.enemies = enemies[:500]
@ -570,7 +570,7 @@ def settings_security_post(v):
if new_email == v.email:
return redirect("/settings/security?error=That email is already yours!")
existing = g.db.query(User.id).options(lazyload('*')).filter(User.id != v.id,
existing = g.db.query(User.id).filter(User.id != v.id,
func.lower(User.email) == new_email.lower()).first()
if existing:
return redirect("/settings/security?error=" +
@ -813,7 +813,7 @@ def settings_block_user(v):
existing = g.db.query(Notification.id).options(lazyload('*')).filter_by(blocksender=v.id, user_id=user.id).first()
existing = g.db.query(Notification.id).filter_by(blocksender=v.id, user_id=user.id).first()
if not existing: send_block_notif(v.id, user.id, f"@{v.username} has blocked you!")
cache.delete_memoized(frontlist)
@ -840,7 +840,7 @@ def settings_unblock_user(v):
existing = g.db.query(Notification.id).options(lazyload('*')).filter_by(unblocksender=v.id, user_id=user.id).first()
existing = g.db.query(Notification.id).filter_by(unblocksender=v.id, user_id=user.id).first()
if not existing: send_unblock_notif(v.id, user.id, f"@{v.username} has unblocked you!")
cache.delete_memoized(frontlist)
@ -914,7 +914,7 @@ def settings_name_change(v):
v=v,
error=f"Username `{new_name}` is already in use.")
v=g.db.query(User).with_for_update().options(lazyload('*')).filter_by(id=v.id).first()
v=g.db.query(User).with_for_update().filter_by(id=v.id).first()
v.username=new_name
v.name_changed_utc=int(time.time())
@ -934,7 +934,7 @@ def settings_name_change(v):
def settings_song_change(v):
song=request.values.get("song").strip()
if song == "" and v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User.id).options(lazyload('*')).filter_by(song=v.song).count() == 1:
if song == "" and v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User.id).filter_by(song=v.song).count() == 1:
os.remove(f"/songs/{v.song}.mp3")
v.song = None
g.db.add(v)
@ -976,7 +976,7 @@ def settings_song_change(v):
error=f"Duration of the video must not exceed 10 minutes.")
if v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User.id).options(lazyload('*')).filter_by(song=v.song).count() == 1:
if v.song and path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User.id).filter_by(song=v.song).count() == 1:
os.remove(f"/songs/{v.song}.mp3")
ydl_opts = {

View File

@ -34,29 +34,29 @@ def participation_stats(v):
day = now - 86400
data = {"valid_users": g.db.query(User.id).options(lazyload('*')).count(),
"private_users": g.db.query(User.id).options(lazyload('*')).filter_by(is_private=True).count(),
"banned_users": g.db.query(User.id).options(lazyload('*')).filter(User.is_banned > 0).count(),
"verified_email_users": g.db.query(User.id).options(lazyload('*')).filter_by(is_activated=True).count(),
"total_coins": g.db.query(func.sum(User.coins).options(lazyload('*'))).scalar(),
"signups_last_24h": g.db.query(User.id).options(lazyload('*')).filter(User.created_utc > day).count(),
"total_posts": g.db.query(Submission.id).options(lazyload('*')).count(),
"posting_users": g.db.query(Submission.author_id).options(lazyload('*')).distinct().count(),
"listed_posts": g.db.query(Submission.id).options(lazyload('*')).filter_by(is_banned=False).filter(Submission.deleted_utc == 0).count(),
"removed_posts": g.db.query(Submission.id).options(lazyload('*')).filter_by(is_banned=True).count(),
"deleted_posts": g.db.query(Submission.id).options(lazyload('*')).filter(Submission.deleted_utc > 0).count(),
"posts_last_24h": g.db.query(Submission.id).options(lazyload('*')).filter(Submission.created_utc > day).count(),
"total_comments": g.db.query(Comment.id).options(lazyload('*')).count(),
"commenting_users": g.db.query(Comment.author_id).options(lazyload('*')).distinct().count(),
"removed_comments": g.db.query(Comment.id).options(lazyload('*')).filter_by(is_banned=True).count(),
"deleted_comments": g.db.query(Comment.id).options(lazyload('*')).filter(Comment.deleted_utc>0).count(),
"comments_last_24h": g.db.query(Comment.id).options(lazyload('*')).filter(Comment.created_utc > day).count(),
"post_votes": g.db.query(Vote.id).options(lazyload('*')).count(),
"post_voting_users": g.db.query(Vote.user_id).options(lazyload('*')).distinct().count(),
"comment_votes": g.db.query(CommentVote.id).options(lazyload('*')).count(),
"comment_voting_users": g.db.query(CommentVote.user_id).options(lazyload('*')).distinct().count(),
"total_awards": g.db.query(AwardRelationship.id).options(lazyload('*')).count(),
"awards_given": g.db.query(AwardRelationship.id).options(lazyload('*')).filter(or_(AwardRelationship.submission_id != None, AwardRelationship.comment_id != None)).count()
data = {"valid_users": g.db.query(User.id).count(),
"private_users": g.db.query(User.id).filter_by(is_private=True).count(),
"banned_users": g.db.query(User.id).filter(User.is_banned > 0).count(),
"verified_email_users": g.db.query(User.id).filter_by(is_activated=True).count(),
"total_coins": g.db.query(func.sum(User.coins)).scalar(),
"signups_last_24h": g.db.query(User.id).filter(User.created_utc > day).count(),
"total_posts": g.db.query(Submission.id).count(),
"posting_users": g.db.query(Submission.author_id).distinct().count(),
"listed_posts": g.db.query(Submission.id).filter_by(is_banned=False).filter(Submission.deleted_utc == 0).count(),
"removed_posts": g.db.query(Submission.id).filter_by(is_banned=True).count(),
"deleted_posts": g.db.query(Submission.id).filter(Submission.deleted_utc > 0).count(),
"posts_last_24h": g.db.query(Submission.id).filter(Submission.created_utc > day).count(),
"total_comments": g.db.query(Comment.id).count(),
"commenting_users": g.db.query(Comment.author_id).distinct().count(),
"removed_comments": g.db.query(Comment.id).filter_by(is_banned=True).count(),
"deleted_comments": g.db.query(Comment.id).filter(Comment.deleted_utc>0).count(),
"comments_last_24h": g.db.query(Comment.id).filter(Comment.created_utc > day).count(),
"post_votes": g.db.query(Vote.id).count(),
"post_voting_users": g.db.query(Vote.user_id).distinct().count(),
"comment_votes": g.db.query(CommentVote.id).count(),
"comment_voting_users": g.db.query(CommentVote.user_id).distinct().count(),
"total_awards": g.db.query(AwardRelationship.id).count(),
"awards_given": g.db.query(AwardRelationship.id).filter(or_(AwardRelationship.submission_id != None, AwardRelationship.comment_id != None)).count()
}
@ -94,11 +94,11 @@ def cached_chart():
daily_times = [time.strftime("%d", time.gmtime(day_cutoffs[i + 1])) for i in range(len(day_cutoffs) - 1)][2:][::-1]
daily_signups = [g.db.query(User.id).options(lazyload('*')).filter(User.created_utc < day_cutoffs[i], User.created_utc > day_cutoffs[i + 1]).count() for i in range(len(day_cutoffs) - 1)][2:][::-1]
daily_signups = [g.db.query(User.id).filter(User.created_utc < day_cutoffs[i], User.created_utc > day_cutoffs[i + 1]).count() for i in range(len(day_cutoffs) - 1)][2:][::-1]
post_stats = [g.db.query(Submission.id).options(lazyload('*')).filter(Submission.created_utc < day_cutoffs[i], Submission.created_utc > day_cutoffs[i + 1], Submission.is_banned == False).count() for i in range(len(day_cutoffs) - 1)][2:][::-1]
post_stats = [g.db.query(Submission.id).filter(Submission.created_utc < day_cutoffs[i], Submission.created_utc > day_cutoffs[i + 1], Submission.is_banned == False).count() for i in range(len(day_cutoffs) - 1)][2:][::-1]
comment_stats = [g.db.query(Comment.id).options(lazyload('*')).filter(Comment.created_utc < day_cutoffs[i], Comment.created_utc > day_cutoffs[i + 1],Comment.is_banned == False, Comment.author_id != 1).count() for i in range(len(day_cutoffs) - 1)][2:][::-1]
comment_stats = [g.db.query(Comment.id).filter(Comment.created_utc < day_cutoffs[i], Comment.created_utc > day_cutoffs[i + 1],Comment.is_banned == False, Comment.author_id != 1).count() for i in range(len(day_cutoffs) - 1)][2:][::-1]
signup_chart = plt.subplot2grid((20, 4), (0, 0), rowspan=5, colspan=4)
posts_chart = plt.subplot2grid((20, 4), (7, 0), rowspan=5, colspan=4)
@ -141,7 +141,7 @@ def patrons(v):
query = g.db.query(
User.id, User.username, User.patron, User.namecolor,
AwardRelationship.kind.label('last_award_kind'), func.count(AwardRelationship.id).label('last_award_count')
).options(lazyload('*')).filter(AwardRelationship.submission_id==None, AwardRelationship.comment_id==None, User.patron > 0) \
).filter(AwardRelationship.submission_id==None, AwardRelationship.comment_id==None, User.patron > 0) \
.group_by(User.username, User.patron, User.id, User.namecolor, AwardRelationship.kind) \
.order_by(User.patron.desc(), AwardRelationship.kind.desc()) \
.join(User).all()
@ -163,7 +163,7 @@ def patrons(v):
@app.get("/badmins")
@auth_desired
def admins(v):
admins = g.db.query(User).options(lazyload('*')).filter_by(admin_level=6).order_by(User.coins.desc()).all()
admins = g.db.query(User).filter_by(admin_level=6).order_by(User.coins.desc()).all()
return render_template("admins.html", v=v, admins=admins)
@ -174,8 +174,8 @@ def log(v):
page=int(request.args.get("page",1))
if v and v.admin_level == 6: actions = g.db.query(ModAction).options(lazyload('*')).order_by(ModAction.id.desc()).offset(25 * (page - 1)).limit(26).all()
else: actions=g.db.query(ModAction).options(lazyload('*')).filter(ModAction.kind!="shadowban", ModAction.kind!="unshadowban", ModAction.kind!="club", ModAction.kind!="unclub", ModAction.kind!="check").order_by(ModAction.id.desc()).offset(25*(page-1)).limit(26).all()
if v and v.admin_level == 6: actions = g.db.query(ModAction).order_by(ModAction.id.desc()).offset(25 * (page - 1)).limit(26).all()
else: actions=g.db.query(ModAction).filter(ModAction.kind!="shadowban", ModAction.kind!="unshadowban", ModAction.kind!="club", ModAction.kind!="unclub", ModAction.kind!="check").order_by(ModAction.id.desc()).offset(25*(page-1)).limit(26).all()
next_exists=len(actions)>25
actions=actions[:25]
@ -191,7 +191,7 @@ def log_item(id, v):
try: id = int(id, 36)
except: abort(404)
action=g.db.query(ModAction).options(lazyload('*')).filter_by(id=id).first()
action=g.db.query(ModAction).filter_by(id=id).first()
if not action:
abort(404)
@ -287,7 +287,7 @@ def settings_profile(v):
def badges(v):
badges = g.db.query(BadgeDef).options(lazyload('*')).all()
badges = g.db.query(BadgeDef).all()
return render_template("badges.html", v=v, badges=badges)
@app.get("/blocks")
@ -295,7 +295,7 @@ def badges(v):
def blocks(v):
blocks=g.db.query(UserBlock).options(lazyload('*')).all()
blocks=g.db.query(UserBlock).all()
users = []
targets = []
for x in blocks:
@ -309,7 +309,7 @@ def blocks(v):
def banned(v):
users = [x for x in g.db.query(User).options(lazyload('*')).filter(User.is_banned > 0, User.unban_utc == 0).all()]
users = [x for x in g.db.query(User).filter(User.is_banned > 0, User.unban_utc == 0).all()]
return render_template("banned.html", v=v, users=users)
@app.get("/formatting")

View File

@ -76,16 +76,16 @@ def steal(v):
@app.get("/rentoids")
@auth_desired
def rentoids(v):
users = g.db.query(User).options(lazyload('*')).filter(User.rent_utc > 0).all()
users = g.db.query(User).filter(User.rent_utc > 0).all()
return render_template("rentoids.html", v=v, users=users)
@app.get("/thiefs")
@auth_desired
def thiefs(v):
successful = g.db.query(User).options(lazyload('*')).filter(User.steal_utc > 0).all()
failed = g.db.query(User).options(lazyload('*')).filter(User.fail_utc > 0).all()
failed2 = g.db.query(User).options(lazyload('*')).filter(User.fail2_utc > 0).all()
successful = g.db.query(User).filter(User.steal_utc > 0).all()
failed = g.db.query(User).filter(User.fail_utc > 0).all()
failed2 = g.db.query(User).filter(User.fail2_utc > 0).all()
return render_template("thiefs.html", v=v, successful=successful, failed=failed, failed2=failed2)
@ -116,7 +116,7 @@ def get_coins(v, username):
@is_not_banned
@validate_formkey
def transfer_coins(v, username):
receiver = g.db.query(User).options(lazyload('*')).filter_by(username=username).first()
receiver = g.db.query(User).filter_by(username=username).first()
if receiver is None: return {"error": "That user doesn't exist."}, 404
@ -130,7 +130,7 @@ def transfer_coins(v, username):
if TAX_RATE and TAX_RECEIVER_ID:
tax = math.ceil(amount*TAX_RATE)
tax_receiver = g.db.query(User).options(lazyload('*')).filter_by(id=TAX_RECEIVER_ID).first()
tax_receiver = g.db.query(User).filter_by(id=TAX_RECEIVER_ID).first()
tax_receiver.coins += tax
log_message = f"[@{v.username}]({v.url}) has transferred {amount} {app.config['COINS_NAME']} to [@{receiver.username}]({receiver.url})"
send_notification(TAX_RECEIVER_ID, log_message)
@ -154,7 +154,7 @@ def transfer_coins(v, username):
@app.get("/leaderboard")
@auth_desired
def leaderboard(v):
users = g.db.query(User).options(lazyload('*'))
users = g.db.query(User)
users1 = users.order_by(User.coins.desc()).limit(25).all()
users2 = users.order_by(User.stored_subscriber_count.desc()).limit(10).all()
users3 = users.order_by(User.post_count.desc()).limit(10).all()
@ -189,7 +189,7 @@ def get_profilecss(username):
def songs(id):
try: id = int(id)
except: return "", 400
user = g.db.query(User).options(lazyload('*')).filter_by(id=id).first()
user = g.db.query(User).filter_by(id=id).first()
if user and user.song: return redirect(f"/song/{user.song}.mp3")
else: abort(404)
@ -213,7 +213,7 @@ def subscribe(v, post_id):
@limiter.limit("1/second")
@auth_required
def unsubscribe(v, post_id):
sub=g.db.query(Subscription).options(lazyload('*')).filter_by(user_id=v.id, submission_id=post_id).first()
sub=g.db.query(Subscription).filter_by(user_id=v.id, submission_id=post_id).first()
if sub:
g.db.delete(sub)
g.db.commit()
@ -232,7 +232,7 @@ def message2(v, username):
message = request.values.get("message", "").strip()[:1000].strip()
existing = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == v.id,
existing = g.db.query(Comment.id).filter(Comment.author_id == v.id,
Comment.sentto == user.id,
Comment.body == message,
).first()
@ -368,8 +368,8 @@ def redditor_moment_redirect(username):
def followers(username, v):
u = get_user(username, v=v)
# if request.host == 'rdrama.net' and u.id == 147: abort(404)
ids = [x[0] for x in g.db.query(Follow.user_id).options(lazyload('*')).filter_by(target_id=u.id).all()]
users = g.db.query(User).options(lazyload('*')).filter(User.id.in_(ids)).all()
ids = [x[0] for x in g.db.query(Follow.user_id).filter_by(target_id=u.id).all()]
users = g.db.query(User).filter(User.id.in_(ids)).all()
return render_template("followers.html", v=v, u=u, users=users)
@app.get("/@<username>/following")
@ -377,8 +377,8 @@ def followers(username, v):
def following(username, v):
u = get_user(username, v=v)
# if request.host == 'rdrama.net' and u.id == 147: abort(404)
ids = [x[0] for x in g.db.query(Follow.target_id).options(lazyload('*')).filter_by(user_id=u.id).all()]
users = g.db.query(User).options(lazyload('*')).filter(User.id.in_(ids)).all()
ids = [x[0] for x in g.db.query(Follow.target_id).filter_by(user_id=u.id).all()]
users = g.db.query(User).filter(User.id.in_(ids)).all()
return render_template("following.html", v=v, u=u, users=users)
@app.get("/views")
@ -412,7 +412,7 @@ def u_username(username, v=None):
else: return render_template("userpage_reserved.html", u=u, v=v)
if v and u.id != v.id:
view = g.db.query(ViewerRelationship).options(lazyload('*')).filter(
view = g.db.query(ViewerRelationship).filter(
and_(
ViewerRelationship.viewer_id == v.id,
ViewerRelationship.user_id == u.id
@ -463,7 +463,7 @@ def u_username(username, v=None):
# If page 1, check for sticky
if page == 1:
sticky = []
sticky = g.db.query(Submission).options(lazyload('*')).filter_by(is_pinned=True, author_id=u.id).all()
sticky = g.db.query(Submission).filter_by(is_pinned=True, author_id=u.id).all()
if sticky:
for p in sticky:
ids = [p.id] + ids
@ -550,7 +550,7 @@ def u_username_comments(username, v=None):
t=request.values.get("t","all")
comments = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == u.id, Comment.parent_submission != None)
comments = g.db.query(Comment.id).filter(Comment.author_id == u.id, Comment.parent_submission != None)
if (not v) or (v.id != u.id and v.admin_level == 0):
comments = comments.filter(Comment.deleted_utc == 0)
@ -619,16 +619,16 @@ def follow_user(username, v):
if target.id==v.id: return {"error": "You can't follow yourself!"}, 400
if g.db.query(Follow).options(lazyload('*')).filter_by(user_id=v.id, target_id=target.id).first(): return {"message": "User followed!"}
if g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).first(): return {"message": "User followed!"}
new_follow = Follow(user_id=v.id, target_id=target.id)
g.db.add(new_follow)
g.db.flush()
target.stored_subscriber_count = g.db.query(Follow.id).options(lazyload('*')).filter_by(target_id=target.id).count()
target.stored_subscriber_count = g.db.query(Follow.id).filter_by(target_id=target.id).count()
g.db.add(target)
existing = g.db.query(Notification.id).options(lazyload('*')).filter_by(followsender=v.id, user_id=target.id).first()
existing = g.db.query(Notification.id).filter_by(followsender=v.id, user_id=target.id).first()
if not existing: send_follow_notif(v.id, target.id, f"@{v.username} has followed you!")
g.db.commit()
@ -644,17 +644,17 @@ def unfollow_user(username, v):
if target.id == CARP_ID: abort(403)
follow = g.db.query(Follow).options(lazyload('*')).filter_by(user_id=v.id, target_id=target.id).first()
follow = g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).first()
if not follow: return {"message": "User unfollowed!"}
g.db.delete(follow)
g.db.flush()
target.stored_subscriber_count = g.db.query(Follow.id).options(lazyload('*')).filter_by(target_id=target.id).count()
target.stored_subscriber_count = g.db.query(Follow.id).filter_by(target_id=target.id).count()
g.db.add(target)
existing = g.db.query(Notification.id).options(lazyload('*')).filter_by(unfollowsender=v.id, user_id=target.id).first()
existing = g.db.query(Notification.id).filter_by(unfollowsender=v.id, user_id=target.id).first()
if not existing: send_unfollow_notif(v.id, target.id, f"@{v.username} has unfollowed you!")
g.db.commit()
@ -667,17 +667,17 @@ def unfollow_user(username, v):
def remove_follow(username, v):
target = get_user(username)
follow = g.db.query(Follow).options(lazyload('*')).filter_by(user_id=target.id, target_id=v.id).first()
follow = g.db.query(Follow).filter_by(user_id=target.id, target_id=v.id).first()
if not follow: return {"message": "Follower removed!"}
g.db.delete(follow)
g.db.flush()
v.stored_subscriber_count = g.db.query(Follow.id).options(lazyload('*')).filter_by(target_id=v.id).count()
v.stored_subscriber_count = g.db.query(Follow.id).filter_by(target_id=v.id).count()
g.db.add(v)
existing = g.db.query(Notification.id).options(lazyload('*')).filter_by(removefollowsender=v.id, user_id=target.id).first()
existing = g.db.query(Notification.id).filter_by(removefollowsender=v.id, user_id=target.id).first()
if not existing: send_unfollow_notif(v.id, target.id, f"@{v.username} has removed your follow!")
g.db.commit()

View File

@ -68,7 +68,7 @@ def api_vote_post(post_id, new, v):
post = get_post(post_id)
existing = g.db.query(Vote).options(lazyload('*')).filter_by(user_id=v.id, submission_id=post.id).first()
existing = g.db.query(Vote).filter_by(user_id=v.id, submission_id=post.id).first()
if existing and existing.vote_type == new: return "", 204
@ -116,8 +116,8 @@ def api_vote_post(post_id, new, v):
try:
g.db.flush()
post.upvotes = g.db.query(Vote.id).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=1).count()
post.downvotes = g.db.query(Vote.id).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=-1).count()
post.upvotes = g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=1).count()
post.downvotes = g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=-1).count()
g.db.add(post)
g.db.commit()
except: g.db.rollback()
@ -141,7 +141,7 @@ def api_vote_comment(comment_id, new, v):
comment = get_comment(comment_id)
existing = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id).first()
existing = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).first()
if existing and existing.vote_type == new: return "", 204
@ -189,8 +189,8 @@ def api_vote_comment(comment_id, new, v):
try:
g.db.flush()
comment.upvotes = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=1).count()
comment.downvotes = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=-1).count()
comment.upvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=1).count()
comment.downvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=-1).count()
g.db.add(comment)
g.db.commit()
except: g.db.rollback()
@ -209,7 +209,7 @@ def api_vote_poll(comment_id, v):
comment_id = int(comment_id)
comment = get_comment(comment_id)
existing = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id).first()
existing = g.db.query(CommentVote).filter_by(user_id=v.id, comment_id=comment.id).first()
if existing and existing.vote_type == new: return "", 204
@ -224,7 +224,7 @@ def api_vote_poll(comment_id, v):
try:
g.db.flush()
comment.upvotes = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=1).count()
comment.upvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=1).count()
g.db.add(comment)
g.db.commit()
except: g.db.rollback()