diff --git a/.gitignore b/.gitignore index dac81c4..ba134b3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ __pycache__ .vscode poetry.lock .venv +.ruff_cache diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 7155c6c..216072e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,7 @@ +[0.2.20] +- added logger +- typing revision + [0.2.19] - fix: stripping user_id diff --git a/resolvers/load.py b/resolvers/load.py index 4e06bb2..4186d4b 100644 --- a/resolvers/load.py +++ b/resolvers/load.py @@ -9,6 +9,11 @@ from services.core import CacheStorage from services.rediscache import redis from services.schema import query +import logging + +logger = logging.getLogger("[resolvers.load] ") +logger.setLevel(logging.DEBUG) + async def get_unread_counter(chat_id: str, member_id: int) -> int: unread = await redis.execute("LLEN", f"chats/{chat_id}/unread/{member_id}") @@ -61,23 +66,27 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Uni author_id = info.context["author_id"] chats = [] if author_id: + logger.debug("got author", author_id) cids = await redis.execute("SMEMBERS", f"chats_by_author/{author_id}") + logger.debug("got cids", cids) + members_online = (await redis.execute("SMEMBERS", "authors-online")) or [] # to show online status + logger.debug("members online", members_online) if isinstance(cids, set): - members_online = (await redis.execute("SMEMBERS", "authors-online")) or [] # TODO: add sort by chat.created_at with in-memory caching chats service cids = list(cids)[offset : (offset + limit)] lock = asyncio.Lock() if len(cids) == 0: - print(f"[resolvers.load] no chats for user with id={author_id}") + logger.debug(f"no chats for user with id={author_id}") r = await create_chat(None, info, members=[2]) # member with id = 2 is discours - print(f"[resolvers.load] created chat: {r['chat_id']}") + logger.debug(f"created chat: {r['chat_id']}") cids.append(r["chat"]["id"]) + logger.debug(f"getting data for {len(cids)} user's chats") for cid in cids: async with lock: chat_str = await redis.execute("GET", f"chats/{cid}") if isinstance(chat_str, str): - print(f"[resolvers.load] redis GET by {cid}: {chat_str}") + logger.debug(f"redis GET by {cid}: {chat_str}") c: ChatPayload = json.loads(chat_str) c["messages"] = (await load_messages(cid, 5, 0)) or [] c["unread"] = await get_unread_counter(cid, author_id) @@ -88,7 +97,12 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Uni if a: a["online"] = a.get("id") in members_online c["members"].append(a) + else: + logger.error(f"cant find author by id {member_id}") chats.append(c) + + else: + logger.error(f"cant find chat by id {cid}") return {"chats": chats, "error": None} diff --git a/services/auth.py b/services/auth.py index af652c7..8153f00 100644 --- a/services/auth.py +++ b/services/auth.py @@ -16,7 +16,6 @@ async def check_auth(req) -> str | None: user_id = "" if token: # Logging the authentication token - # print(f"[services.auth] checking auth token: {token}") query_name = "validate_jwt_token" operation = "ValidateToken" headers = {