cache-when-created
All checks were successful
Deploy on push / deploy (push) Successful in 28s

This commit is contained in:
Untone 2024-05-18 13:57:30 +03:00
parent bc01dfb125
commit 7d97f40826
2 changed files with 22 additions and 4 deletions

View File

@ -40,7 +40,7 @@ index_settings = {
"title": {"type": "text", "analyzer": "ru"},
"subtitle": {"type": "text", "analyzer": "ru"},
"lead": {"type": "text", "analyzer": "ru"},
"media": {"type": "text", "analyzer": "ru"}
"media": {"type": "text", "analyzer": "ru"},
}
},
}
@ -138,12 +138,21 @@ class SearchService:
result = json.loads(result)
if isinstance(result, dict):
mapping = result.get(self.index_name, {}).get("mappings")
if mapping and mapping['properties'].keys() != expected_mapping['properties'].keys():
if (
mapping
and mapping["properties"].keys()
!= expected_mapping["properties"].keys()
):
logger.debug("Найдена структура индексации:")
logger.debug("\n" + json.dumps(mapping, indent=2, ensure_ascii=False))
logger.debug(
"\n" + json.dumps(mapping, indent=2, ensure_ascii=False)
)
logger.debug("Ожидаемая структура индексации:")
logger.debug("\n" + json.dumps(expected_mapping, indent=2, ensure_ascii=False))
logger.debug(
"\n"
+ json.dumps(expected_mapping, indent=2, ensure_ascii=False)
)
logger.warn(
"[!!!] Требуется другая структура индексации и переиндексация всех данных"

View File

@ -6,8 +6,12 @@ from starlette.exceptions import HTTPException
from starlette.requests import Request
from starlette.responses import JSONResponse
from sqlalchemy import select
from orm.author import Author
from services.db import local_session
from services.cache import cache_author
from resolvers.stat import get_with_stat
class WebhookEndpoint(HTTPEndpoint):
@ -56,6 +60,11 @@ class WebhookEndpoint(HTTPEndpoint):
author = Author(user=user_id, slug=slug, name=name, pic=pic)
session.add(author)
session.commit()
[author_with_stat] = get_with_stat(
select(Author).filter(Author.id == author.id)
)
if author_with_stat:
await cache_author(author_with_stat)
return JSONResponse({"status": "success"})
except HTTPException as e: