fix repeated "top poster of the day" notifications and console errors that happen when a new poster of the day is selected
parent
8d367b7b94
commit
170bc8feb0
|
@ -101,6 +101,9 @@ def cron_fn(every_5m, every_1d, every_1mo):
|
||||||
_expire_blocks_mutes_exiles()
|
_expire_blocks_mutes_exiles()
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
|
||||||
|
_set_top_poster_of_the_day_id()
|
||||||
|
g.db.commit()
|
||||||
|
|
||||||
if every_1mo:
|
if every_1mo:
|
||||||
_give_marseybux_salary()
|
_give_marseybux_salary()
|
||||||
g.db.commit()
|
g.db.commit()
|
||||||
|
@ -376,3 +379,25 @@ def _expire_blocks_mutes_exiles():
|
||||||
for holeblock in holeblocks:
|
for holeblock in holeblocks:
|
||||||
send_repeatable_notification(holeblock.user_id, f"Your block of /h/{holeblock.hole} has passed 1 month and expired!")
|
send_repeatable_notification(holeblock.user_id, f"Your block of /h/{holeblock.hole} has passed 1 month and expired!")
|
||||||
g.db.delete(holeblock)
|
g.db.delete(holeblock)
|
||||||
|
|
||||||
|
|
||||||
|
def _set_top_poster_of_the_day_id():
|
||||||
|
t = int(time.time()) - 86400
|
||||||
|
|
||||||
|
db = db_session()
|
||||||
|
|
||||||
|
user = db.query(User, func.sum(Post.upvotes)).join(Post, Post.author_id == User.id).filter(
|
||||||
|
Post.created_utc > t,
|
||||||
|
User.admin_level == 0,
|
||||||
|
).group_by(User).order_by(func.sum(Post.upvotes).desc()).first()
|
||||||
|
|
||||||
|
if not user: return SNAPPY_ID
|
||||||
|
|
||||||
|
user = user[0]
|
||||||
|
|
||||||
|
t = datetime.datetime.now()
|
||||||
|
db.flush()
|
||||||
|
send_notification(user.id, f":marseyjam: You're the Top Poster of the Day for the day of {t.year}-{t.month}-{t.day} :marseyjam:")
|
||||||
|
badge_grant(badge_id=327, user=user)
|
||||||
|
|
||||||
|
cache.set("top_poster_of_the_day". user.id)
|
||||||
|
|
|
@ -137,34 +137,8 @@ def bar_position():
|
||||||
def emoji_count():
|
def emoji_count():
|
||||||
return g.db.query(Emoji).filter_by(submitter_id=None).count()
|
return g.db.query(Emoji).filter_by(submitter_id=None).count()
|
||||||
|
|
||||||
@cache.memoize(timeout=86400)
|
|
||||||
def top_poster_of_the_day_id():
|
|
||||||
t = int(time.time()) - 86400
|
|
||||||
|
|
||||||
db = db_session()
|
|
||||||
|
|
||||||
user = db.query(User, func.sum(Post.upvotes)).join(Post, Post.author_id == User.id).filter(
|
|
||||||
Post.created_utc > t,
|
|
||||||
User.admin_level == 0,
|
|
||||||
).group_by(User).order_by(func.sum(Post.upvotes).desc()).first()
|
|
||||||
|
|
||||||
if not user: return SNAPPY_ID
|
|
||||||
|
|
||||||
user = user[0]
|
|
||||||
|
|
||||||
t = datetime.datetime.now()
|
|
||||||
db.flush()
|
|
||||||
send_notification(user.id, f":marseyjam: You're the Top Poster of the Day for the day of {t.year}-{t.month}-{t.day} :marseyjam:")
|
|
||||||
badge_grant(badge_id=327, user=user)
|
|
||||||
uid = user.id
|
|
||||||
|
|
||||||
db.commit()
|
|
||||||
db.close()
|
|
||||||
|
|
||||||
return uid
|
|
||||||
|
|
||||||
def top_poster_of_the_day():
|
def top_poster_of_the_day():
|
||||||
uid = top_poster_of_the_day_id()
|
uid = cache.get("top_poster_of_the_day") or SNAPPY_ID
|
||||||
user = g.db.query(User).filter_by(id=uid).one()
|
user = g.db.query(User).filter_by(id=uid).one()
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue