This commit is contained in:
parent
c5d21c3554
commit
fbcee18db1
|
@ -49,35 +49,33 @@ async def get_my_rates_shouts(_, info, shouts):
|
||||||
"""
|
"""
|
||||||
author_dict = info.context.get("author") if info.context else None
|
author_dict = info.context.get("author") if info.context else None
|
||||||
author_id = author_dict.get("id") if author_dict else None
|
author_id = author_dict.get("id") if author_dict else None
|
||||||
|
|
||||||
if not author_id:
|
if not author_id:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
try:
|
try:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(
|
select(Reaction)
|
||||||
Reaction
|
.where(
|
||||||
).where(
|
|
||||||
and_(
|
and_(
|
||||||
Reaction.shout.in_(shouts),
|
Reaction.shout.in_(shouts),
|
||||||
Reaction.reply_to.is_(None),
|
Reaction.reply_to.is_(None),
|
||||||
Reaction.created_by == author_id,
|
Reaction.created_by == author_id,
|
||||||
Reaction.deleted_at.is_(None),
|
Reaction.deleted_at.is_(None),
|
||||||
Reaction.kind.in_([ReactionKind.LIKE.value, ReactionKind.DISLIKE.value])
|
Reaction.kind.in_([ReactionKind.LIKE.value, ReactionKind.DISLIKE.value]),
|
||||||
)
|
)
|
||||||
).order_by(
|
)
|
||||||
Reaction.shout,
|
.order_by(Reaction.shout, Reaction.created_at.desc())
|
||||||
Reaction.created_at.desc()
|
.distinct(Reaction.shout)
|
||||||
).distinct(Reaction.shout)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
result = session.execute(stmt).all()
|
result = session.execute(stmt).all()
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
"shout_id": row[0].shout, # Получаем shout_id из объекта Reaction
|
"shout_id": row[0].shout, # Получаем shout_id из объекта Reaction
|
||||||
"my_rate": row[0].kind # Получаем kind (my_rate) из объекта Reaction
|
"my_rate": row[0].kind, # Получаем kind (my_rate) из объекта Reaction
|
||||||
}
|
}
|
||||||
for row in result
|
for row in result
|
||||||
]
|
]
|
||||||
|
|
|
@ -161,9 +161,9 @@ def query_with_stat(info):
|
||||||
)
|
)
|
||||||
.filter(Reaction.reply_to.is_(None))
|
.filter(Reaction.reply_to.is_(None))
|
||||||
.label("rating"),
|
.label("rating"),
|
||||||
func.max(Reaction.created_at).filter(Reaction.kind == ReactionKind.COMMENT.value).label(
|
func.max(Reaction.created_at)
|
||||||
"last_commented_at"
|
.filter(Reaction.kind == ReactionKind.COMMENT.value)
|
||||||
),
|
.label("last_commented_at"),
|
||||||
)
|
)
|
||||||
.where(Reaction.deleted_at.is_(None))
|
.where(Reaction.deleted_at.is_(None))
|
||||||
.group_by(Reaction.shout)
|
.group_by(Reaction.shout)
|
||||||
|
@ -177,7 +177,7 @@ def query_with_stat(info):
|
||||||
"rating",
|
"rating",
|
||||||
func.coalesce(stats_subquery.c.rating, 0),
|
func.coalesce(stats_subquery.c.rating, 0),
|
||||||
"last_commented_at",
|
"last_commented_at",
|
||||||
func.coalesce(stats_subquery.c.last_commented_at, 0)
|
func.coalesce(stats_subquery.c.last_commented_at, 0),
|
||||||
).label("stat")
|
).label("stat")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
import httpx
|
|
||||||
|
|
||||||
from cache.cache import get_cached_author_by_user_id
|
from cache.cache import get_cached_author_by_user_id
|
||||||
from resolvers.stat import get_with_stat
|
from resolvers.stat import get_with_stat
|
||||||
from services.schema import request_graphql_data
|
from services.schema import request_graphql_data
|
||||||
|
|
|
@ -113,7 +113,7 @@ class SearchService:
|
||||||
async def info(self):
|
async def info(self):
|
||||||
if not SEARCH_ENABLED:
|
if not SEARCH_ENABLED:
|
||||||
return {"status": "disabled"}
|
return {"status": "disabled"}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return get_indices_stats()
|
return get_indices_stats()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -158,7 +158,7 @@ class SearchService:
|
||||||
def index(self, shout):
|
def index(self, shout):
|
||||||
if not SEARCH_ENABLED:
|
if not SEARCH_ENABLED:
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.client:
|
if self.client:
|
||||||
logger.info(f"Индексируем пост {shout.id}")
|
logger.info(f"Индексируем пост {shout.id}")
|
||||||
index_body = {
|
index_body = {
|
||||||
|
@ -184,7 +184,7 @@ class SearchService:
|
||||||
async def search(self, text, limit, offset):
|
async def search(self, text, limit, offset):
|
||||||
if not SEARCH_ENABLED:
|
if not SEARCH_ENABLED:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
logger.info(f"Ищем: {text} {offset}+{limit}")
|
logger.info(f"Ищем: {text} {offset}+{limit}")
|
||||||
search_body = {
|
search_body = {
|
||||||
"query": {"multi_match": {"query": text, "fields": ["title", "lead", "subtitle", "body", "media"]}}
|
"query": {"multi_match": {"query": text, "fields": ["title", "lead", "subtitle", "body", "media"]}}
|
||||||
|
@ -226,5 +226,6 @@ async def search_text(text: str, limit: int = 50, offset: int = 0):
|
||||||
payload = await search_service.search(text, limit, offset)
|
payload = await search_service.search(text, limit, offset)
|
||||||
return payload
|
return payload
|
||||||
|
|
||||||
|
|
||||||
# Проверить что URL корректный
|
# Проверить что URL корректный
|
||||||
OPENSEARCH_URL = os.getenv('OPENSEARCH_URL', 'rc1a-3n5pi3bhuj9gieel.mdb.yandexcloud.net')
|
OPENSEARCH_URL = os.getenv("OPENSEARCH_URL", "rc1a-3n5pi3bhuj9gieel.mdb.yandexcloud.net")
|
||||||
|
|
|
@ -27,9 +27,7 @@ async def check_webhook_existence() -> bool:
|
||||||
|
|
||||||
operation = "GetWebhooks"
|
operation = "GetWebhooks"
|
||||||
query_name = "_webhooks"
|
query_name = "_webhooks"
|
||||||
variables = {
|
variables = {"params": {}}
|
||||||
"params": {}
|
|
||||||
}
|
|
||||||
# https://docs.authorizer.dev/core/graphql-api#_webhooks
|
# https://docs.authorizer.dev/core/graphql-api#_webhooks
|
||||||
gql = {
|
gql = {
|
||||||
"query": f"query {operation}($params: GetWebhooksRequest!)"
|
"query": f"query {operation}($params: GetWebhooksRequest!)"
|
||||||
|
@ -64,9 +62,7 @@ async def create_webhook_endpoint():
|
||||||
"event_name": "user.login",
|
"event_name": "user.login",
|
||||||
"endpoint": "https://core.dscrs.site/new-author",
|
"endpoint": "https://core.dscrs.site/new-author",
|
||||||
"enabled": True,
|
"enabled": True,
|
||||||
"headers": {
|
"headers": {"Authorization": WEBHOOK_SECRET},
|
||||||
"Authorization": WEBHOOK_SECRET
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gql = {
|
gql = {
|
||||||
|
@ -76,7 +72,6 @@ async def create_webhook_endpoint():
|
||||||
+ "}",
|
+ "}",
|
||||||
"variables": variables,
|
"variables": variables,
|
||||||
"operationName": operation,
|
"operationName": operation,
|
||||||
|
|
||||||
}
|
}
|
||||||
result = await request_graphql_data(gql, headers=headers)
|
result = await request_graphql_data(gql, headers=headers)
|
||||||
logger.info(result)
|
logger.info(result)
|
||||||
|
|
|
@ -15,4 +15,4 @@ DEV_SERVER_PID_FILE_NAME = "dev-server.pid"
|
||||||
MODE = "development" if "dev" in sys.argv else "production"
|
MODE = "development" if "dev" in sys.argv else "production"
|
||||||
|
|
||||||
ADMIN_SECRET = environ.get("AUTH_SECRET") or "nothing"
|
ADMIN_SECRET = environ.get("AUTH_SECRET") or "nothing"
|
||||||
WEBHOOK_SECRET = environ.get("WEBHOOK_SECRET") or "nothing-else"
|
WEBHOOK_SECRET = environ.get("WEBHOOK_SECRET") or "nothing-else"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user