diff --git a/resolvers/load.py b/resolvers/load.py index ed73ac0..4206c4b 100644 --- a/resolvers/load.py +++ b/resolvers/load.py @@ -75,13 +75,13 @@ async def load_chats( chats = [] try: if author_id: - logger.debug("got author", author_id) + logger.debug(f"got author {author_id}") cids = await redis.execute("SMEMBERS", f"chats_by_author/{author_id}") - logger.debug("got cids", cids) + logger.debug(f"got cids {cids}") members_online = ( await redis.execute("SMEMBERS", "authors-online") ) or [] # to show online status - logger.debug("members online", members_online) + logger.debug(f"members online: {members_online}") if isinstance(cids, set): # TODO: add sort by chat.created_at with in-memory caching chats service cids = list(cids)[offset : (offset + limit)] @@ -89,9 +89,11 @@ async def load_chats( if len(cids) == 0: 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 - if isinstance(r, dict) and "chat" in r: - logger.debug(f"created chat: {r['chat']['id']}") - cids.append(r["chat"]["id"]) + if isinstance(r, dict) and "chat" in r and isinstance(r['chat'], dict): + chat_id = r['chat'].get('id') + if chat_id: + logger.debug(f"created chat: {chat_id}") + cids.append(chat_id) logger.debug(f"getting data for {len(cids)} user's chats") for cid in cids: diff --git a/services/core.py b/services/core.py index f6ad00f..77c94b1 100644 --- a/services/core.py +++ b/services/core.py @@ -64,8 +64,8 @@ class CacheStorage: self = CacheStorage async with self.lock: result = get_all_authors() - logger.info(f"cache loaded {len(result)}") - if result: + if isinstance(result, list): + logger.info(f"cache loaded {len(result)}") CacheStorage.authors = result for a in result: user_id = a.get("user")