fmt
All checks were successful
Deploy on push / deploy (push) Successful in 26s

This commit is contained in:
Untone 2024-05-18 11:00:46 +03:00
parent 3d90d9c81d
commit a749ade30b
6 changed files with 38 additions and 12 deletions

View File

@ -7,7 +7,6 @@ from services.db import Base
# from sqlalchemy_utils import TSVectorType # from sqlalchemy_utils import TSVectorType
class AuthorRating(Base): class AuthorRating(Base):
__tablename__ = "author_rating" __tablename__ = "author_rating"

View File

@ -11,7 +11,12 @@ from resolvers.author import ( # search_authors,
) )
from resolvers.community import get_communities_all, get_community from resolvers.community import get_communities_all, get_community
from resolvers.editor import create_shout, delete_shout, update_shout from resolvers.editor import create_shout, delete_shout, update_shout
from resolvers.follower import follow, get_shout_followers, get_topic_followers, unfollow from resolvers.follower import (
follow,
get_shout_followers,
get_topic_followers,
unfollow,
)
from resolvers.notifier import ( from resolvers.notifier import (
load_notifications, load_notifications,
notification_mark_seen, notification_mark_seen,
@ -35,7 +40,12 @@ from resolvers.reader import (
load_shouts_search, load_shouts_search,
load_shouts_unrated, load_shouts_unrated,
) )
from resolvers.topic import get_topic, get_topics_all, get_topics_by_author, get_topics_by_community from resolvers.topic import (
get_topic,
get_topics_all,
get_topics_by_author,
get_topics_by_community,
)
from services.triggers import events_register from services.triggers import events_register
events_register() events_register()

View File

@ -8,7 +8,12 @@ from sqlalchemy.orm import aliased
from sqlalchemy.sql import not_ from sqlalchemy.sql import not_
from orm.author import Author from orm.author import Author
from orm.notification import Notification, NotificationAction, NotificationEntity, NotificationSeen from orm.notification import (
Notification,
NotificationAction,
NotificationEntity,
NotificationSeen,
)
from orm.shout import Shout from orm.shout import Shout
from services.auth import login_required from services.auth import login_required
from services.db import local_session from services.db import local_session

View File

@ -31,9 +31,7 @@ def add_author_stat_columns(q):
func.count(distinct(aliased_shout.shout)).label("shouts_stat") func.count(distinct(aliased_shout.shout)).label("shouts_stat")
) )
aliased_follower = aliased(AuthorFollower) aliased_follower = aliased(AuthorFollower)
q = q.outerjoin( q = q.outerjoin(aliased_follower, aliased_follower.author == Author.id).add_columns(
aliased_follower, aliased_follower.author == Author.id
).add_columns(
func.count(distinct(aliased_follower.follower)).label("followers_stat") func.count(distinct(aliased_follower.follower)).label("followers_stat")
) )

View File

@ -12,7 +12,10 @@ ELASTIC_HOST = os.environ.get("ELASTIC_HOST", "").replace("https://", "")
ELASTIC_USER = os.environ.get("ELASTIC_USER", "") ELASTIC_USER = os.environ.get("ELASTIC_USER", "")
ELASTIC_PASSWORD = os.environ.get("ELASTIC_PASSWORD", "") ELASTIC_PASSWORD = os.environ.get("ELASTIC_PASSWORD", "")
ELASTIC_PORT = os.environ.get("ELASTIC_PORT", 9200) ELASTIC_PORT = os.environ.get("ELASTIC_PORT", 9200)
ELASTIC_URL = os.environ.get("ELASTIC_URL", f"https://{ELASTIC_USER}:{ELASTIC_PASSWORD}@{ELASTIC_HOST}:{ELASTIC_PORT}") ELASTIC_URL = os.environ.get(
"ELASTIC_URL",
f"https://{ELASTIC_USER}:{ELASTIC_PASSWORD}@{ELASTIC_HOST}:{ELASTIC_PORT}",
)
REDIS_TTL = 86400 # 1 день в секундах REDIS_TTL = 86400 # 1 день в секундах
index_settings = { index_settings = {
@ -113,7 +116,9 @@ class SearchService:
mapping = result.get(self.index_name, {}).get("mappings") mapping = result.get(self.index_name, {}).get("mappings")
if mapping and mapping != expected_mapping: if mapping and mapping != expected_mapping:
logger.debug(f"Найдена структура индексации: {mapping}") logger.debug(f"Найдена структура индексации: {mapping}")
logger.warn("Требуется другая структура индексации, переиндексация") logger.warn(
"Требуется другая структура индексации, переиндексация"
)
await self.recreate_index() await self.recreate_index()
else: else:
logger.error("клиент не инициализован, невозможно проверить индекс") logger.error("клиент не инициализован, невозможно проверить индекс")
@ -121,7 +126,9 @@ class SearchService:
async def recreate_index(self): async def recreate_index(self):
if self.client: if self.client:
async with self.lock: async with self.lock:
self.client.indices.delete(index=self.index_name, ignore_unavailable=True) self.client.indices.delete(
index=self.index_name, ignore_unavailable=True
)
await self.check_index() await self.check_index()
else: else:
logger.error("клиент не инициализован, невозможно пересоздать индекс") logger.error("клиент не инициализован, невозможно пересоздать индекс")
@ -136,7 +143,9 @@ class SearchService:
async def perform_index(self, shout): async def perform_index(self, shout):
if self.client: if self.client:
self.client.index(index=self.index_name, id=str(shout.id), body=shout.dict()) self.client.index(
index=self.index_name, id=str(shout.id), body=shout.dict()
)
async def search(self, text, limit, offset): async def search(self, text, limit, offset):
logger.debug(f"Ищем: {text}") logger.debug(f"Ищем: {text}")

View File

@ -7,7 +7,12 @@ from typing import Dict
# ga # ga
from google.analytics.data_v1beta import BetaAnalyticsDataClient from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import DateRange, Dimension, Metric, RunReportRequest from google.analytics.data_v1beta.types import (
DateRange,
Dimension,
Metric,
RunReportRequest,
)
from orm.author import Author from orm.author import Author
from orm.shout import Shout, ShoutAuthor, ShoutTopic from orm.shout import Shout, ShoutAuthor, ShoutTopic