diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 18c261d3..75cd42a8 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,7 @@ - packages upgrade, isort - separated stats queries for author and topic - fix: feed featured filter +- fts search removed [0.3.2] - redis cache for what author follows diff --git a/pyproject.toml b/pyproject.toml index a0bc2c7e..a50b4ceb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,6 @@ opensearch-py = "^2.5.0" httpx = "^0.27.0" dogpile-cache = "^1.3.1" colorlog = "^6.8.2" -sqlalchemy-searchable = "^2.1.0" [tool.poetry.group.dev.dependencies] ruff = "^0.3.5" diff --git a/resolvers/__init__.py b/resolvers/__init__.py index 9526d9db..dbc3f35e 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -1,4 +1,4 @@ -from resolvers.author import ( +from resolvers.author import ( # search_authors, get_author, get_author_followers, get_author_follows, @@ -7,12 +7,16 @@ from resolvers.author import ( get_author_id, get_authors_all, load_authors_by, - search_authors, update_author, ) from resolvers.community import get_communities_all, get_community 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 ( load_notifications, notification_mark_seen, @@ -36,7 +40,12 @@ from resolvers.reader import ( load_shouts_search, 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 events_register() @@ -52,7 +61,7 @@ __all__ = [ "load_authors_by", "rate_author", "update_author", - "search_authors", + ## "search_authors", # community "get_community", "get_communities_all", diff --git a/resolvers/author.py b/resolvers/author.py index 0700287a..bfe6be78 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -3,7 +3,6 @@ import time from sqlalchemy import and_, desc, or_, select, text from sqlalchemy.orm import aliased -from sqlalchemy_searchable import search from orm.author import Author, AuthorFollower from orm.shout import ShoutAuthor, ShoutTopic @@ -323,9 +322,3 @@ async def get_author_followers(_, _info, slug: str): logger.error(exc) logger.error(traceback.format_exc()) return [] - - -@query.field("search_authors") -async def search_authors(_, _info, what: str): - q = search(select(Author), what) - return get_with_stat(q) diff --git a/resolvers/notifier.py b/resolvers/notifier.py index 8a3b9a91..8ce824e3 100644 --- a/resolvers/notifier.py +++ b/resolvers/notifier.py @@ -8,7 +8,12 @@ from sqlalchemy.orm import aliased from sqlalchemy.sql import not_ 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 services.auth import login_required from services.db import local_session diff --git a/resolvers/stat.py b/resolvers/stat.py index d16905fc..77274f74 100644 --- a/resolvers/stat.py +++ b/resolvers/stat.py @@ -172,24 +172,23 @@ def get_with_stat(q): is_author = f"{q}".lower().startswith("select author") # is_topic = f"{q}".lower().startswith("select topic") result = [] - add_stat_handler = ( - add_author_stat_columns if is_author else add_topic_stat_columns - ) + if is_author: + q = add_author_stat_columns(q) + else: + q = add_topic_stat_columns(q) with local_session() as session: - result = session.execute(add_stat_handler(q)) + result = session.execute(q) for cols in result: entity = cols[0] stat = dict() stat["shouts"] = cols[1] stat["followers"] = cols[2] - stat["authors"] = ( - get_author_authors_stat(entity.id) - if is_author - else get_topic_authors_stat(entity.id) - ) if is_author: + stat["authors"] = get_author_authors_stat(entity.id) stat["comments"] = get_author_comments_stat(entity.id) + else: + stat["authors"] = get_topic_authors_stat(entity.id) entity.stat = stat records.append(entity) except Exception as exc: diff --git a/schema/query.graphql b/schema/query.graphql index dfceef79..21fa60ea 100644 --- a/schema/query.graphql +++ b/schema/query.graphql @@ -4,7 +4,7 @@ type Query { get_author_id(user: String!): Author get_authors_all: [Author] load_authors_by(by: AuthorsBy!, limit: Int, offset: Int): [Author] - search_authors(what: String!): [Author] + # search_authors(what: String!): [Author] # community get_community: Community diff --git a/services/db.py b/services/db.py index 7030f3bb..d71e8142 100644 --- a/services/db.py +++ b/services/db.py @@ -9,11 +9,13 @@ from sqlalchemy import JSON, Column, Engine, Integer, create_engine, event, exc, from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import Session, configure_mappers from sqlalchemy.sql.schema import Table -from sqlalchemy_searchable import make_searchable from services.logger import root_logger as logger from settings import DB_URL +# from sqlalchemy_searchable import make_searchable + + # Подключение к базе данных SQLAlchemy engine = create_engine(DB_URL, echo=False, pool_size=10, max_overflow=20) inspector = inspect(engine) @@ -69,7 +71,7 @@ class Base(declarative_base()): setattr(self, key, value) -make_searchable(Base.metadata) +# make_searchable(Base.metadata) Base.metadata.create_all(bind=engine) diff --git a/services/viewed.py b/services/viewed.py index 4e4ee4b5..277bb8a5 100644 --- a/services/viewed.py +++ b/services/viewed.py @@ -7,7 +7,12 @@ from typing import Dict # ga 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.shout import Shout, ShoutAuthor, ShoutTopic @@ -59,10 +64,9 @@ class ViewedStorage: self = ViewedStorage try: if os.path.exists(VIEWS_FILEPATH): - self.file_modification_timestamp = os.path.getmtime(VIEWS_FILEPATH) - self.start_date = datetime.fromtimestamp( - self.file_modification_timestamp - ).strftime("%Y-%m-%d") + start_date_int = os.path.getmtime(VIEWS_FILEPATH) + start_date_str = datetime.fromtimestamp(start_date_int).strftime('%Y-%m-%d') + self.start_date = start_date_str now_date = datetime.now().strftime("%Y-%m-%d") if now_date == self.start_date: