diff --git a/drama/classes/user.py b/drama/classes/user.py index ac3e45f01..3d668d68c 100644 --- a/drama/classes/user.py +++ b/drama/classes/user.py @@ -25,6 +25,7 @@ class User(Base, Stndrd, Age_times): theme = Column(String, default='dark') themecolor = Column(String, default='ff66ac') song = Column(String) + highres = Column(String) profileurl = Column(String) bannerurl = Column(String) patron = Column(Boolean, default=False) diff --git a/drama/routes/admin.py b/drama/routes/admin.py index feb0acdc3..a1f5eb432 100644 --- a/drama/routes/admin.py +++ b/drama/routes/admin.py @@ -17,7 +17,6 @@ from drama.classes import * from drama.classes.domains import reasons as REASONS from flask import * import matplotlib.pyplot as plt -from .front import frontlist from drama.__main__ import app, cache @@ -54,7 +53,7 @@ def flagged_posts(v): listing = [p.id for p in posts] next_exists = (len(listing) == 26) - listing = listing[0:25] + listing = listing[:25] listing = get_posts(listing, v=v) @@ -75,7 +74,7 @@ def image_posts_listing(v): posts = [x.id for x in posts] next_exists = (len(posts) == 26) - posts = posts[0:25] + posts = posts[:25] posts = get_posts(posts, v=v) @@ -105,7 +104,7 @@ def flagged_comments(v): listing = [p.id for p in posts] next_exists = (len(listing) == 26) - listing = listing[0:25] + listing = listing[:25] listing = get_comments(listing, v=v) @@ -221,7 +220,7 @@ def users_list(v): users = [x for x in users] next_exists = (len(users) == 26) - users = users[0:25] + users = users[:25] return render_template("admin/new_users.html", v=v, @@ -408,7 +407,7 @@ def admin_removed(v): next_exists = len(ids) == 26 - ids = ids[0:25] + ids = ids[:25] posts = get_posts(ids, v=v) @@ -568,7 +567,7 @@ def shadowban(user_id, v): target_user_id=user.id, ) g.db.add(ma) - cache.delete_memoized(frontlist) + return "", 204 @@ -590,7 +589,7 @@ def unshadowban(user_id, v): target_user_id=user.id, ) g.db.add(ma) - cache.delete_memoized(frontlist) + return "", 204 @@ -739,7 +738,7 @@ def ban_post(post_id, v): g.db.add(post) - cache.delete_memoized(frontlist) + ma=ModAction( kind="ban_post", @@ -773,7 +772,7 @@ def unban_post(post_id, v): g.db.add(post) - cache.delete_memoized(frontlist) + return "", 204 @@ -810,7 +809,7 @@ def api_sticky_post(post_id, v): post.stickied = not (post.stickied) g.db.add(post) g.db.commit() - cache.delete_memoized(frontlist) + return "", 204 diff --git a/drama/routes/feeds.py b/drama/routes/feeds.py index 464801091..033edcb56 100644 --- a/drama/routes/feeds.py +++ b/drama/routes/feeds.py @@ -17,7 +17,7 @@ def feeds_user(sort='hot', t='all'): page=page, t=t, v=None, - ids_only=False) + ) domain = environ.get( "domain", environ.get( diff --git a/drama/routes/front.py b/drama/routes/front.py index 58203cc27..512237cb6 100644 --- a/drama/routes/front.py +++ b/drama/routes/front.py @@ -69,8 +69,8 @@ def notifications(v): render_replies=True, is_notification_page=True) -@cache.memoize(timeout=1500) -def frontlist(v=None, sort="hot", page=1,t="all", ids_only=True, filter_words='', **kwargs): + +def frontlist(v=None, sort="hot", page=1,t="all", filter_words='', **kwargs): posts = g.db.query(Submission).options(lazyload('*')).filter_by(is_banned=False,stickied=False,private=False).filter(Submission.deleted_utc == 0) if v and v.admin_level == 0: @@ -169,12 +169,7 @@ def frontlist(v=None, sort="hot", page=1,t="all", ids_only=True, filter_words='' post.views = post.views + random.randint(7,10) g.db.add(post) - posts = [x for x in posts if not (x.author and x.author.shadowbanned) or (v and v.id == x.author_id)][:26] - - if ids_only: - posts = [x.id for x in posts] - return posts - return posts + return [x for x in posts if not (x.author and x.author.shadowbanned) or (v and v.id == x.author_id)][:26] @app.get("/") @app.get("/api/v1/listing") @@ -198,7 +193,7 @@ def front_all(v): sort=request.args.get("sort", defaultsorting) t=request.args.get('t', defaulttime) - ids = frontlist(sort=sort, + posts = frontlist(sort=sort, page=page, t=t, v=v, @@ -208,11 +203,8 @@ def front_all(v): ) # check existence of next page - next_exists = (len(ids) == 26) - ids = ids[0:25] - - # check if ids exist - posts = get_posts(ids, v=v) + next_exists = (len(posts) == 26) + posts = posts[:25] if request.path == "/": return render_template("home.html", v=v, listing=posts, next_exists=next_exists, sort=sort, t=t, page=page) else: return jsonify({"data": [x.json for x in posts], "next_exists": next_exists}) @@ -311,7 +303,7 @@ def changelog(v): # check existence of next page next_exists = (len(ids) == 26) - ids = ids[0:25] + ids = ids[:25] # check if ids exist posts = get_posts(ids, v=v) @@ -426,7 +418,7 @@ def all_comments(v): next_exists = len(idlist) == 26 - idlist = idlist[0:25] + idlist = idlist[:25] return {"html": lambda: render_template("home_comments.html", v=v, diff --git a/drama/routes/oauth.py b/drama/routes/oauth.py index a5f8eccaa..cad56bb0d 100644 --- a/drama/routes/oauth.py +++ b/drama/routes/oauth.py @@ -229,7 +229,7 @@ def request_api_keys(v): app_name=request.form.get('name'), redirect_uri=request.form.get('redirect_uri'), author_id=v.id, - description=request.form.get("description")[0:256] + description=request.form.get("description")[:256] ) g.db.add(new_app) @@ -267,7 +267,7 @@ def edit_oauth_app(v, aid): app.redirect_uri = request.form.get('redirect_uri') app.app_name = request.form.get('name') - app.description = request.form.get("description")[0:256] + app.description = request.form.get("description")[:256] g.db.add(app) diff --git a/drama/routes/posts.py b/drama/routes/posts.py index 5b0398b5f..ee349c45e 100644 --- a/drama/routes/posts.py +++ b/drama/routes/posts.py @@ -13,7 +13,6 @@ from drama.helpers.thumbs import * from drama.helpers.alerts import send_notification from drama.helpers.discord import send_message from drama.classes import * -from .front import frontlist from flask import * from io import BytesIO from drama.__main__ import app, limiter, cache @@ -60,7 +59,7 @@ def publish(pid, v): if not post.author_id == v.id: abort(403) post.private = False g.db.add(post) - cache.delete_memoized(frontlist) + g.db.commit() return "", 204 @@ -941,7 +940,7 @@ def submit_post(v): # spin off thumbnail generation and csam detection as new threads if (new_post.url or request.files.get('file')) and (v.is_activated or request.headers.get('cf-ipcountry')!="T1"): thumbs(new_post) - cache.delete_memoized(frontlist) + cache.delete_memoized(User.userpagelisting) g.db.commit() @@ -1061,7 +1060,7 @@ def delete_post_pid(pid, v): g.db.add(post) - cache.delete_memoized(frontlist) + return "", 204 @@ -1075,7 +1074,7 @@ def undelete_post_pid(pid, v): if not post.author_id == v.id: abort(403) post.deleted_utc =0 g.db.add(post) - cache.delete_memoized(frontlist) + return "", 204 @app.get("/embed/post/") diff --git a/drama/routes/search.py b/drama/routes/search.py index 88f4584b7..c846a157d 100644 --- a/drama/routes/search.py +++ b/drama/routes/search.py @@ -215,7 +215,7 @@ def searchposts(v, search_type="posts"): total, ids = searchlisting(criteria, v=v, page=page, t=t, sort=sort) next_exists = (len(ids) == 26) - ids = ids[0:25] + ids = ids[:25] posts = get_posts(ids, v=v) @@ -262,7 +262,7 @@ def searchcomments(v): total, ids = searchcommentlisting(criteria, v=v, page=page, t=t, sort=sort) next_exists = (len(ids) == 26) - ids = ids[0:25] + ids = ids[:25] comments = get_comments(ids, v=v) @@ -305,7 +305,7 @@ def searchusers(v, search_type="posts"): users=[x for x in users.offset(25 * (page-1)).limit(26)] next_exists=(len(users)==26) - users=users[0:25] + users=users[:25] diff --git a/drama/routes/settings.py b/drama/routes/settings.py index 22f87b67b..2838a2c4b 100644 --- a/drama/routes/settings.py +++ b/drama/routes/settings.py @@ -5,8 +5,7 @@ from drama.helpers.filters import filter_comment_html from drama.helpers.markdown import * from drama.helpers.discord import remove_user, set_nick from drama.mail import * -from .front import frontlist -from drama.__main__ import app, cache +=from drama.__main__ import app, cache import youtube_dl valid_username_regex = re.compile("^[a-zA-Z0-9_\-]{3,25}$") @@ -159,7 +158,7 @@ def settings_profile_post(v): def changelogsub(v): v.changelogsub = not v.changelogsub g.db.add(v) - cache.delete_memoized(frontlist) + return "", 204 @app.post("/settings/namecolor") @@ -460,7 +459,7 @@ def settings_block_user(v): ) g.db.add(new_block) - cache.delete_memoized(frontlist) + existing = g.db.query(Notification).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!") @@ -482,7 +481,7 @@ def settings_unblock_user(v): g.db.delete(x) - cache.delete_memoized(frontlist) + existing = g.db.query(Notification).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!") diff --git a/drama/routes/users.py b/drama/routes/users.py index 73e2af129..eaade85f3 100644 --- a/drama/routes/users.py +++ b/drama/routes/users.py @@ -291,7 +291,7 @@ def u_username(username, v=None): # we got 26 items just to see if a next page exists next_exists = (len(ids) == 26) - ids = ids[0:25] + ids = ids[:25] # If page 1, check for sticky if page == 1: @@ -391,7 +391,7 @@ def u_username_comments(username, v=None): # we got 26 items just to see if a next page exists next_exists = (len(ids) == 26) - ids = ids[0:25] + ids = ids[:25] listing = get_comments(ids, v=v) @@ -497,7 +497,7 @@ def saved_posts(v, username): next_exists=len(ids)==26 - ids=ids[0:25] + ids=ids[:25] listing = get_posts(ids, v=v) @@ -524,7 +524,7 @@ def saved_comments(v, username): next_exists=len(ids)==26 - ids=ids[0:25] + ids=ids[:25] listing = get_comments(ids, v=v, sort="new")