forked from retoor/devplacepy
Update
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
from devplacepy.cache import TTLCache
|
||||
from .core import db, get_table
|
||||
from .relations import get_blocked_uids
|
||||
|
||||
@@ -7,6 +8,9 @@ from .relations import get_blocked_uids
|
||||
PAGE_SIZE = 25
|
||||
|
||||
|
||||
_user_post_count_cache = TTLCache(ttl=15, max_size=2000)
|
||||
|
||||
|
||||
def paginate(
|
||||
table,
|
||||
*clauses,
|
||||
@@ -74,10 +78,19 @@ def paginate_diverse(
|
||||
return interleave_by_author(rows, uid_key=uid_key), next_cursor
|
||||
|
||||
|
||||
def clear_user_post_count(user_uid: str) -> None:
|
||||
_user_post_count_cache.pop(user_uid)
|
||||
|
||||
|
||||
def get_user_post_count(user_uid: str) -> int:
|
||||
cached = _user_post_count_cache.get(user_uid)
|
||||
if cached is not None:
|
||||
return cached
|
||||
if "posts" not in db.tables:
|
||||
return 0
|
||||
return get_table("posts").count(user_uid=user_uid, deleted_at=None)
|
||||
count = get_table("posts").count(user_uid=user_uid, deleted_at=None)
|
||||
_user_post_count_cache.set(user_uid, count)
|
||||
return count
|
||||
|
||||
|
||||
def build_pagination(page, total, per_page=25):
|
||||
|
||||
Reference in New Issue
Block a user