0.2.15
Some checks failed
deploy / deploy (push) Failing after 1m58s

This commit is contained in:
2023-11-24 02:00:28 +03:00
parent c150d28447
commit a63cf24812
12 changed files with 187 additions and 139 deletions

View File

@@ -1,8 +1,8 @@
import asyncio
import json
import httpx
from services.rediscache import redis
from orm.shout import Shout
from resolvers.reader import load_shouts_by
class SearchService:
@@ -20,15 +20,13 @@ class SearchService:
cached = await redis.execute("GET", text)
if not cached:
async with SearchService.lock:
options = {
"title": text,
"body": text,
"limit": limit,
"offset": offset,
}
# FIXME: use elastic request here
payload = await load_shouts_by(None, None, options)
await redis.execute("SET", text, json.dumps(payload))
return payload
# Use httpx to send a request to ElasticSearch
async with httpx.AsyncClient() as client:
search_url = f"https://search.discours.io/search?q={text}"
response = await client.get(search_url)
if response.status_code == 200:
payload = response.json()
await redis.execute("SET", text, payload)
return json.loads(payload)
else:
return json.loads(cached)