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,15 +58,8 @@ 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
|
|
||||||
await pipeline.get(f"chats/{cid}")
|
|
||||||
# Execute the pipeline
|
|
||||||
result = await pipeline.execute()
|
|
||||||
# Get the result of the GET command
|
|
||||||
c = result[0]
|
|
||||||
print(f"got chat {c}")
|
|
||||||
if c:
|
if c:
|
||||||
c = json.loads(c)
|
c = json.loads(c)
|
||||||
c["messages"] = await load_messages(cid, 5, 0)
|
c["messages"] = await load_messages(cid, 5, 0)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user