race-fix7
This commit is contained in:
parent
95bf812ae2
commit
55c75f2a2e
|
@ -6,6 +6,9 @@ from services.auth import login_required
|
||||||
from services.schema import query
|
from services.schema import query
|
||||||
from .chats import create_chat
|
from .chats import create_chat
|
||||||
from .unread import get_unread_counter
|
from .unread import get_unread_counter
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
lock = asyncio.Lock()
|
||||||
|
|
||||||
|
|
||||||
# NOTE: not an API handler
|
# NOTE: not an API handler
|
||||||
|
@ -55,35 +58,28 @@ async def load_chats(_, info, limit: int = 50, offset: int = 0):
|
||||||
cids.append(r["chat"]["id"])
|
cids.append(r["chat"]["id"])
|
||||||
|
|
||||||
for cid in cids:
|
for cid in cids:
|
||||||
# Start a pipeline
|
async with lock:
|
||||||
pipeline = await redis.pipeline()
|
c = await redis.execute("GET", f"chats/{cid}")
|
||||||
# Add the GET command to the pipeline
|
if c:
|
||||||
await pipeline.get(f"chats/{cid}")
|
c = json.loads(c)
|
||||||
# Execute the pipeline
|
c["messages"] = await load_messages(cid, 5, 0)
|
||||||
result = await pipeline.execute()
|
c["unread"] = await get_unread_counter(cid, author_id)
|
||||||
# Get the result of the GET command
|
member_ids = c["members"].copy()
|
||||||
c = result[0]
|
c["members"] = []
|
||||||
print(f"got chat {c}")
|
for member_id in member_ids:
|
||||||
if c:
|
a = await get_author(member_id)
|
||||||
c = json.loads(c)
|
if a:
|
||||||
c["messages"] = await load_messages(cid, 5, 0)
|
c["members"].append(
|
||||||
c["unread"] = await get_unread_counter(cid, author_id)
|
{
|
||||||
member_ids = c["members"].copy()
|
"id": a.id,
|
||||||
c["members"] = []
|
"slug": a.slug,
|
||||||
for member_id in member_ids:
|
"userpic": a.userpic,
|
||||||
a = await get_author(member_id)
|
"name": a.name,
|
||||||
if a:
|
"lastSeen": a.lastSeen,
|
||||||
c["members"].append(
|
"online": a.id in members_online,
|
||||||
{
|
}
|
||||||
"id": a.id,
|
)
|
||||||
"slug": a.slug,
|
chats.append(c)
|
||||||
"userpic": a.userpic,
|
|
||||||
"name": a.name,
|
|
||||||
"lastSeen": a.lastSeen,
|
|
||||||
"online": a.id in members_online,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
chats.append(c)
|
|
||||||
return {"chats": chats, "error": None}
|
return {"chats": chats, "error": None}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user