fix pfp caching
parent
b23dc76d78
commit
ca1b716010
|
@ -6,6 +6,7 @@ from sqlalchemy.orm import joinedload, selectinload, Query
|
|||
|
||||
from files.classes import Comment, CommentVote, Hat, Sub, Submission, User, UserBlock, Vote
|
||||
from files.helpers.config.const import AUTOJANNY_ID
|
||||
from files.__main__ import cache
|
||||
|
||||
def sanitize_username(username:str) -> str:
|
||||
if not username: return username
|
||||
|
@ -351,3 +352,13 @@ def get_sub_by_name(sub:str, v:Optional[User]=None, graceful=False) -> Optional[
|
|||
if graceful: return None
|
||||
else: abort(404)
|
||||
return sub
|
||||
|
||||
@cache.memoize(timeout=8640000)
|
||||
def get_profile_picture(identifier:Union[int, str]) -> str:
|
||||
print(identifier, flush=True)
|
||||
if isinstance(identifier, int):
|
||||
x = get_account(identifier, graceful=True)
|
||||
else:
|
||||
x = get_user(identifier, graceful=True)
|
||||
|
||||
return x.profile_url if x else 'not_found'
|
||||
|
|
|
@ -571,6 +571,9 @@ def settings_images_profile(v):
|
|||
v.profileurl = imageurl
|
||||
g.db.add(v)
|
||||
|
||||
cache.delete_memoized(get_profile_picture, v.id)
|
||||
cache.delete_memoized(get_profile_picture, v.username)
|
||||
cache.delete_memoized(get_profile_picture, v.original_username)
|
||||
|
||||
return render_template("settings/personal.html", v=v, msg="Profile picture successfully updated.")
|
||||
|
||||
|
|
|
@ -1135,21 +1135,19 @@ def remove_follow(username, v):
|
|||
|
||||
return {"message": f"@{target.username} has been removed as a follower!"}
|
||||
|
||||
|
||||
@app.get("/pp/<int:id>")
|
||||
@app.get("/uid/<int:id>/pic")
|
||||
@app.get("/uid/<int:id>/pic/profile")
|
||||
@cache.memoize(timeout=86400)
|
||||
@limiter.exempt
|
||||
def user_profile_uid(id):
|
||||
x = get_account(id)
|
||||
return redirect(x.profile_url)
|
||||
return redirect(get_profile_picture(id))
|
||||
|
||||
@app.get("/@<username>/pic")
|
||||
@cache.memoize(timeout=86400)
|
||||
@limiter.exempt
|
||||
def user_profile_name(username):
|
||||
x = get_user(username)
|
||||
return redirect(x.profile_url)
|
||||
return redirect(get_profile_picture(username))
|
||||
|
||||
|
||||
def get_saves_and_subscribes(v, template, relationship_cls, page:int, standalone=False):
|
||||
if relationship_cls in {SaveRelationship, Subscription}:
|
||||
|
|
Loading…
Reference in New Issue