This commit is contained in:
parent
f52db8f9e5
commit
71000aad35
|
@ -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]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user