Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

Commit

Permalink
Fix useer not found errors in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RealistikDash committed Oct 5, 2020
1 parent 50cc23d commit 89f8a04
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion handlers/levelextras.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def level_comments_handler(request : aiohttp.web.Request):
for comment in comments.results:
comment : Comment
try:
comment_user = await user_helper.get_object(await user_helper.accid_userid(comment.user_id))
comment_user = await user_helper.get_object(await user_helper.userid_accid(comment.user_id))
except AssertionError: # The user does not exist
logging.debug(f"Failed searching for user {comment.user_id}. Should be skipped.")
else:
Expand Down
17 changes: 17 additions & 0 deletions helpers/userhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self):
self.object_cache = {}
self.extra_object_cache = {}
self.accid_userid_cache = {}
self.userid_accid_cache = {}
self.relationships = {}
self.user_str_cache = {}

Expand Down Expand Up @@ -90,6 +91,22 @@ async def accid_userid(self, account_id : int) -> int:
await self._cache_aid_uid(account_id)
return self.accid_userid_cache[account_id]

async def _cache_uid_aid(self, user_id: int) -> None:
"""Caches an account id to user id value."""
user_id =int(user_id)
async with myconn.conn.cursor() as mycursor:
await mycursor.execute("SELECT extID FROM users WHERE userID = %s LIMIT 1", (user_id,))
acc_id = await mycursor.fetchone()
assert acc_id is not None
self.userid_accid_cache[user_id] = acc_id[0]

async def userid_accid(self, user_id : int) -> int:
"""Returns the accountID of a user with given userID."""
user_id = int(user_id)
if user_id not in dict_keys(self.userid_accid_cache):
await self._cache_uid_aid(user_id)
return self.userid_accid_cache[user_id]

async def recache_object(self, account_id: int) -> None:
"""Forces a user object to recache."""
account_id = int(account_id)
Expand Down

0 comments on commit 89f8a04

Please sign in to comment.