viwed-fix+fmt+outerjoin-fix
All checks were successful
Deploy on push / deploy (push) Successful in 1m1s

This commit is contained in:
Untone 2024-04-27 01:41:47 +03:00
parent 89956d6240
commit 2e4d70db28
9 changed files with 43 additions and 31 deletions

View File

@ -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

View File

@ -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"

View File

@ -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",

View File

@ -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)

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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)

View File

@ -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: