forked from retoor/devplacepy
Update
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from devplacepy.cache import TTLCache
|
||||
from devplacepy.config import (
|
||||
AWARD_DISPLAY_HOURS_DEFAULT,
|
||||
AWARD_GIVE_COOLDOWN_HOURS_DEFAULT,
|
||||
@@ -111,10 +112,22 @@ def recompute_user_award_stats(receiver_uid: str) -> None:
|
||||
users.update(payload, ["uid"])
|
||||
|
||||
|
||||
_prominence_cache = TTLCache(ttl=15, max_size=500)
|
||||
|
||||
|
||||
def award_is_prominent(user: dict | None) -> bool:
|
||||
if not user or not user.get("last_award_at") or not user.get("last_award_uid"):
|
||||
return False
|
||||
award = resolve_by_slug(_awards_table(), user["last_award_uid"])
|
||||
cached = _prominence_cache.get(user["last_award_uid"])
|
||||
if cached is not None:
|
||||
return cached
|
||||
prominent = _compute_prominence(user["last_award_uid"])
|
||||
_prominence_cache.set(user["last_award_uid"], prominent)
|
||||
return prominent
|
||||
|
||||
|
||||
def _compute_prominence(award_uid: str) -> bool:
|
||||
award = resolve_by_slug(_awards_table(), award_uid)
|
||||
if not award or not award.get("generated_at"):
|
||||
return False
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user