search-debug
All checks were successful
deploy / deploy (push) Successful in 1m22s

This commit is contained in:
Untone 2023-12-19 15:03:27 +03:00
parent f52db8f9e5
commit 71000aad35

View File

@ -24,13 +24,14 @@ class SearchService:
if not cached: if not cached:
async with SearchService.lock: async with SearchService.lock:
# Use aiohttp to send a request to ElasticSearch # Use aiohttp to send a request to ElasticSearch
# TODO: add limit offset usage
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
search_url = f"https://search.discours.io/search?q={text}" search_url = f"https://search.discours.io/search?q={text}"
async with session.get(search_url) as response: async with session.get(search_url) as response:
if response.status == 200: if response.status == 200:
payload = await response.json() payload = await response.json()
await redis.execute("SET", text, json.dumps(payload)) await redis.execute("SET", text, json.dumps(payload))
return payload return payload[offset : offset + limit]
else: else:
return json.loads(cached) print(f"[services.search] response: {response.status} {response.text}")
else:
return json.loads(cached)[offset : offset + limit]