forked from rDrama/rDrama
only query the columns u need
parent
77e16c017f
commit
ffba8b3b2d
|
@ -26,13 +26,13 @@ from files.__main__ import app, cache, limiter
|
||||||
def _mark_comment_as_read(cid, vid):
|
def _mark_comment_as_read(cid, vid):
|
||||||
db = db_session()
|
db = db_session()
|
||||||
|
|
||||||
notif = db.query(Notification).filter_by(comment_id=cid, user_id=vid, read=False).one_or_none()
|
notif = db.query(Notification).options(load_only(Notification.read)).filter_by(comment_id=cid, user_id=vid, read=False).one_or_none()
|
||||||
|
|
||||||
if notif:
|
if notif and not notif.read:
|
||||||
notif.read = True
|
notif.read = True
|
||||||
db.add(notif)
|
db.add(notif)
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
db.close()
|
db.close()
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ from files.__main__ import app, limiter, redis_instance
|
||||||
def _add_post_view(pid):
|
def _add_post_view(pid):
|
||||||
db = db_session()
|
db = db_session()
|
||||||
|
|
||||||
p = db.get(Post, pid)
|
p = db.query(Post).filter_by(id=pid).options(load_only(Post.views)).one()
|
||||||
p.views += 1
|
p.views += 1
|
||||||
db.add(p)
|
db.add(p)
|
||||||
|
|
||||||
|
@ -290,11 +290,11 @@ def thumbnail_thread(pid:int, vid:int):
|
||||||
else:
|
else:
|
||||||
return f"{post_url}/{fragment_url}"
|
return f"{post_url}/{fragment_url}"
|
||||||
|
|
||||||
p = db.get(Post, pid)
|
p = db.query(Post).filter_by(id=pid).options(load_only(Post.url)).one()
|
||||||
|
|
||||||
if not p or not p.url:
|
if not p or not p.url:
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
p = db.get(Post, pid)
|
p = db.query(Post).filter_by(id=pid).options(load_only(Post.url)).one()
|
||||||
|
|
||||||
if not p or not p.url: return
|
if not p or not p.url: return
|
||||||
|
|
||||||
|
@ -391,7 +391,8 @@ def thumbnail_thread(pid:int, vid:int):
|
||||||
for chunk in image_req.iter_content(1024):
|
for chunk in image_req.iter_content(1024):
|
||||||
file.write(chunk)
|
file.write(chunk)
|
||||||
|
|
||||||
v = db.get(User, vid)
|
v = db.query(User).filter_by(id=vid).options(load_only(User.id, User.patron)).one()
|
||||||
|
|
||||||
url = process_image(name, v, resize=99, uploader_id=p.author_id, db=db)
|
url = process_image(name, v, resize=99, uploader_id=p.author_id, db=db)
|
||||||
if url:
|
if url:
|
||||||
p.thumburl = url
|
p.thumburl = url
|
||||||
|
|
|
@ -809,7 +809,8 @@ def settings_song_change_mp3(v):
|
||||||
|
|
||||||
def _change_song_youtube(vid, id):
|
def _change_song_youtube(vid, id):
|
||||||
db = db_session()
|
db = db_session()
|
||||||
v = db.get(User, vid)
|
|
||||||
|
v = db.query(User).filter_by(id=vid).options(load_only(User.song)).one()
|
||||||
|
|
||||||
if v.song and path.isfile(f"/songs/{v.song}.mp3") and db.query(User).filter_by(song=v.song).count() == 1:
|
if v.song and path.isfile(f"/songs/{v.song}.mp3") and db.query(User).filter_by(song=v.song).count() == 1:
|
||||||
os.remove(f"/songs/{v.song}.mp3")
|
os.remove(f"/songs/{v.song}.mp3")
|
||||||
|
|
|
@ -29,7 +29,8 @@ from files.__main__ import app, cache, limiter
|
||||||
def _add_profile_view(vid, uid):
|
def _add_profile_view(vid, uid):
|
||||||
db = db_session()
|
db = db_session()
|
||||||
|
|
||||||
view = db.query(ViewerRelationship).filter_by(viewer_id=vid, user_id=uid).one_or_none()
|
view = db.query(ViewerRelationship).options(load_only(ViewerRelationship.viewer_id)).filter_by(viewer_id=vid, user_id=uid).one_or_none()
|
||||||
|
|
||||||
if view: view.last_view_utc = int(time.time())
|
if view: view.last_view_utc = int(time.time())
|
||||||
else: view = ViewerRelationship(viewer_id=vid, user_id=uid)
|
else: view = ViewerRelationship(viewer_id=vid, user_id=uid)
|
||||||
db.add(view)
|
db.add(view)
|
||||||
|
|
Loading…
Reference in New Issue