try to speed up hole creation (testing on staging)

master
Aevann 2024-01-14 11:00:11 +02:00
parent 9752c2340a
commit c1daa4ef42
2 changed files with 22 additions and 13 deletions

View File

@ -114,25 +114,27 @@ def notif_comment_mention(p):
return create_comment(text_html), text
def add_notif(cid, uid, text, pushnotif_url=''):
def add_notif(cid, uid, text, pushnotif_url='', check_existing=True):
if uid in BOT_IDs: return
if hasattr(g, 'v') and g.v and g.v.shadowbanned and g.db.query(User.admin_level).filter_by(id=uid).one()[0] < PERMS['USER_SHADOWBAN']:
return
existing = g.db.query(Notification.user_id).filter_by(comment_id=cid, user_id=uid).one_or_none()
if not existing:
notif = Notification(comment_id=cid, user_id=uid)
g.db.add(notif)
if check_existing:
existing = g.db.query(Notification.user_id).filter_by(comment_id=cid, user_id=uid).one_or_none()
if existing: return
if not pushnotif_url:
pushnotif_url = f'{SITE_FULL}/notification/{cid}'
notif = Notification(comment_id=cid, user_id=uid)
g.db.add(notif)
if ' has mentioned you: [' in text:
text = text.split(':')[0] + '!'
if not pushnotif_url:
pushnotif_url = f'{SITE_FULL}/notification/{cid}'
if not request.path.startswith('/submit'):
push_notif({uid}, 'New notification', text, pushnotif_url)
if ' has mentioned you: [' in text:
text = text.split(':')[0] + '!'
if not request.path.startswith('/submit'):
push_notif({uid}, 'New notification', text, pushnotif_url)
def NOTIFY_USERS(text, v, oldtext=None, ghost=False, obj=None, followers_ping=True, commenters_ping_post_id=None):

View File

@ -389,10 +389,17 @@ def create_sub2(v):
mod = Mod(user_id=v.id, hole=hole.name)
g.db.add(mod)
text_html = sanitize(f":!marseyparty: /h/{hole} has been created by @{v.username} :marseyparty:", blackjack="notification")
cid = create_comment(text_html)
t = time.time() - 604800
notified_users = [x[0] for x in g.db.query(User.id).filter(User.admin_level >= PERMS['NOTIFICATIONS_HOLE_CREATION'], User.id != v.id, User.last_active > t)]
for user in notified_users:
send_repeatable_notification(user, f":!marseyparty: /h/{hole} has been created by @{v.username} :marseyparty:")
for uid in notified_users:
add_notif(cid, uid, text, check_existing=False)
return redirect(f"/h/{hole}")