Partial fix for performance issues with mentions
This commit is contained in:
parent
e63a021c61
commit
658eacb45d
2 changed files with 17 additions and 9 deletions
|
@ -154,18 +154,12 @@ def sanitize(sanitized, alert=False, comment=False, edit=False):
|
||||||
sanitized = sanitized.replace(i.group(0), f'''<p><a href="/id/{u.id}"><img loading="lazy" src="/pp/{u.id}">@{u.username}</a>''')
|
sanitized = sanitized.replace(i.group(0), f'''<p><a href="/id/{u.id}"><img loading="lazy" src="/pp/{u.id}">@{u.username}</a>''')
|
||||||
else:
|
else:
|
||||||
sanitized = reddit_regex.sub(r'\1<a href="https://old.reddit.com/\2" rel="nofollow noopener noreferrer">/\2</a>', sanitized)
|
sanitized = reddit_regex.sub(r'\1<a href="https://old.reddit.com/\2" rel="nofollow noopener noreferrer">/\2</a>', sanitized)
|
||||||
|
|
||||||
sanitized = sub_regex.sub(r'\1<a href="/\2">/\2</a>', sanitized)
|
sanitized = sub_regex.sub(r'\1<a href="/\2">/\2</a>', sanitized)
|
||||||
|
|
||||||
captured = []
|
|
||||||
for i in mention_regex.finditer(sanitized):
|
for i in mention_regex.finditer(sanitized):
|
||||||
if i.group(0) in captured: continue
|
|
||||||
captured.append(i.group(0))
|
|
||||||
|
|
||||||
u = get_user(i.group(2), graceful=True)
|
u = get_user(i.group(2), graceful=True)
|
||||||
|
|
||||||
if u and (not (g.v and g.v.any_block_exists(u)) or g.v.admin_level > 1):
|
if u and (not (g.v and g.v.any_block_exists(u)) or g.v.admin_level > 1):
|
||||||
sanitized = sanitized.replace(i.group(0), f'''{i.group(1)}<a href="/id/{u.id}"><img loading="lazy" src="/pp/{u.id}">@{u.username}</a>''')
|
sanitized = sanitized.replace(i.group(0), f'''{i.group(1)}<a href="/id/{u.id}"><img loading="lazy" src="/pp/{u.id}">@{u.username}</a>''', 1)
|
||||||
|
|
||||||
|
|
||||||
sanitized = imgur_regex.sub(r'\1_d.webp?maxwidth=9999&fidelity=high', sanitized)
|
sanitized = imgur_regex.sub(r'\1_d.webp?maxwidth=9999&fidelity=high', sanitized)
|
||||||
|
|
|
@ -1079,6 +1079,8 @@ def remove_follow(username, v):
|
||||||
|
|
||||||
return {"message": "Follower removed!"}
|
return {"message": "Follower removed!"}
|
||||||
|
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
@app.get("/pp/<id>")
|
@app.get("/pp/<id>")
|
||||||
@app.get("/uid/<id>/pic")
|
@app.get("/uid/<id>/pic")
|
||||||
@app.get("/uid/<id>/pic/profile")
|
@app.get("/uid/<id>/pic/profile")
|
||||||
|
@ -1090,10 +1092,22 @@ def user_profile_uid(v, id):
|
||||||
try: id = int(id, 36)
|
try: id = int(id, 36)
|
||||||
except: abort(404)
|
except: abort(404)
|
||||||
|
|
||||||
x=get_account(id)
|
name = f"/pp/{id}"
|
||||||
return redirect(x.profile_url)
|
path = cache.get(name)
|
||||||
|
tout = 5 * 60 # 5 min
|
||||||
|
|
||||||
|
if not path:
|
||||||
|
user = get_account(id)
|
||||||
|
path = urlparse(user.profile_url).path
|
||||||
|
if path.startswith('/assets'):
|
||||||
|
path = path.lstrip('/')
|
||||||
|
path = os.path.join(app.root_path, path)
|
||||||
|
cache.set(name,path,timeout=tout)
|
||||||
|
|
||||||
|
return send_file(path)
|
||||||
|
|
||||||
@app.get("/@<username>/pic")
|
@app.get("/@<username>/pic")
|
||||||
|
@cache.cached(timeout=50)
|
||||||
@limiter.exempt
|
@limiter.exempt
|
||||||
@auth_required
|
@auth_required
|
||||||
def user_profile_name(v, username):
|
def user_profile_name(v, username):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue