remotes/1693045480750635534/spooky-22
Aevann1 2021-11-02 17:17:16 +02:00
parent 362c02678f
commit 9387b2f425
11 changed files with 39 additions and 39 deletions

View File

@ -162,7 +162,7 @@ class Comment(Base):
if self.level == 1: return self.post
else: return g.db.query(Comment).get(self.parent_comment_id)
else: return g.db.query(Comment).options(lazyload('*')).get(self.parent_comment_id)
@property
@lazy

View File

@ -251,7 +251,7 @@ class User(Base):
@lazy
def banned_by(self):
if not self.is_suspended: return None
return g.db.query(User).filter_by(id=self.is_banned).first()
return g.db.query(User).options(lazyload('*')).filter_by(id=self.is_banned).first()
def has_badge(self, badgedef_id):
return self.badges.filter_by(badge_id=badgedef_id).first()

View File

@ -171,7 +171,7 @@ 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).order_by(AwardRelationship.id.desc()).first().id
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():
if u.patron == 1: procoins = 2000
elif u.patron == 2: procoins = 5000
@ -245,7 +245,7 @@ def image_posts_listing(v):
try: page = int(request.values.get('page', 1))
except: page = 1
posts = g.db.query(Submission).order_by(Submission.id.desc())
posts = g.db.query(Submission).options(lazyload('*')).order_by(Submission.id.desc())
firstrange = 25 * (page - 1)
secondrange = firstrange+26
@ -327,7 +327,7 @@ def disablesignups(v):
@admin_level_required(4)
def badge_grant_get(v):
badge_types = g.db.query(BadgeDef).all()
badge_types = g.db.query(BadgeDef).options(lazyload('*')).all()
errors = {"already_owned": "That user already has that badge.",
"no_user": "That user doesn't exist."
@ -538,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).get(u2).username}")
return redirect(f"/admin/alt_votes?u1={g.db.query(User).get(u1).username}&u2={g.db.query(User).options(lazyload('*')).get(u2).username}")
@app.get("/admin/removed")
@ -1068,7 +1068,7 @@ def admin_dump_cache(v):
@admin_level_required(4)
def admin_banned_domains(v):
banned_domains = g.db.query(BannedDomain).all()
banned_domains = g.db.query(BannedDomain).options(lazyload('*')).all()
return render_template("admin/banned_domains.html", v=v, banned_domains=banned_domains)
@app.post("/admin/banned_domains")

View File

@ -234,7 +234,7 @@ def shop(v):
},
}
for useraward in g.db.query(AwardRelationship).filter(AwardRelationship.user_id == v.id, AwardRelationship.submission_id == None, AwardRelationship.comment_id == None).all():
for useraward in g.db.query(AwardRelationship).options(lazyload('*')).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
@ -250,7 +250,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)).scalar()
sales = g.db.query(Vote.id).count() + g.db.query(CommentVote.id).count() - g.db.query(func.sum(User.coins).options(lazyload('*'))).scalar()
return render_template("shop.html", awards=list(AWARDS.values()), v=v, sales=sales)
@ -473,7 +473,7 @@ def buy(v, award):
g.db.add(v)
g.db.flush()
thing = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first().id
thing = g.db.query(AwardRelationship).options(lazyload('*')).order_by(AwardRelationship.id.desc()).first().id
thing += 1
award = AwardRelationship(id=thing, user_id=v.id, kind=award)
@ -746,7 +746,7 @@ def admin_userawards_post(v):
notify_awards = {}
latest = g.db.query(AwardRelationship).order_by(AwardRelationship.id.desc()).first()
latest = g.db.query(AwardRelationship).options(lazyload('*')).order_by(AwardRelationship.id.desc()).first()
thing = latest.id
for key, value in request.values.items():
@ -902,7 +902,7 @@ def items(v):
},
}
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
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
if v.patron == 1: discount = 0.10
elif v.patron == 2: discount = 0.15

View File

@ -768,7 +768,7 @@ def edit_comment(cid, v):
mentions = soup.find_all("a", href=re.compile("^/@(\w+)"))
if len(mentions) > 0:
notifs = g.db.query(Notification)
notifs = g.db.query(Notification).options(lazyload('*'))
for mention in mentions:
username = mention["href"].split("@")[1]

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).filter(Comment.sentto==0).order_by(Comment.created_utc.desc()).offset(25*(page-1)).limit(26).all()
comments = g.db.query(Comment).options(lazyload('*')).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).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).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()
next_exists = (len(comments) > 25)
comments = comments[:25]
elif posts:
@ -216,8 +216,8 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
pins = g.db.query(Submission.id).options(lazyload('*')).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).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()]
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()]
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

View File

@ -321,7 +321,7 @@ 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).count() #paranoid
users_count = g.db.query(User.id).options(lazyload('*')).count() #paranoid
if id_1 == 0 and users_count < 7: admin_level=6
else: admin_level=0

View File

@ -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).all()
apps = g.db.query(OauthApp).options(lazyload('*')).all()
return render_template("admin/apps.html", v=v, apps=apps)

View File

@ -171,7 +171,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:
shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned != None).all()]
comments = g.db.query(Comment).filter(Comment.parent_submission == post.id, Comment.author_id != AUTOPOLLER_ACCOUNT, Comment.author_id.notin_(shadowbanned))
comments = g.db.query(Comment).options(lazyload('*')).filter(Comment.parent_submission == post.id, Comment.author_id != AUTOPOLLER_ACCOUNT, Comment.author_id.notin_(shadowbanned))
if sort == "new":
comments = comments.order_by(Comment.created_utc.desc())
@ -386,11 +386,11 @@ def thumbnail_thread(pid):
db = db_session()
post = db.query(Submission).filter_by(id=pid).first()
post = db.query(Submission).options(lazyload('*')).filter_by(id=pid).first()
if not post:
time.sleep(5)
post = db.query(Submission).filter_by(id=pid).first()
post = db.query(Submission).options(lazyload('*')).filter_by(id=pid).first()
fetch_url=post.url

View File

@ -34,28 +34,28 @@ def participation_stats(v):
day = now - 86400
data = {"valid_users": g.db.query(User.id).count(),
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)).scalar(),
"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).count(),
"posting_users": g.db.query(Submission.author_id).distinct().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).count(),
"commenting_users": g.db.query(Comment.author_id).distinct().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).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(),
"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()
}
@ -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).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()
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()
next_exists=len(actions)>25
actions=actions[:25]
@ -287,7 +287,7 @@ def settings_profile(v):
def badges(v):
badges = g.db.query(BadgeDef).all()
badges = g.db.query(BadgeDef).options(lazyload('*')).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).all()
blocks=g.db.query(UserBlock).options(lazyload('*')).all()
users = []
targets = []
for x in blocks:

View File

@ -116,7 +116,7 @@ def get_coins(v, username):
@is_not_banned
@validate_formkey
def transfer_coins(v, username):
receiver = g.db.query(User).filter_by(username=username).first()
receiver = g.db.query(User).options(lazyload('*')).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).filter_by(id=TAX_RECEIVER_ID).first()
tax_receiver = g.db.query(User).options(lazyload('*')).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)