This commit is contained in:
@@ -3,11 +3,6 @@ import time
|
||||
|
||||
from sqlalchemy import desc, select, text
|
||||
|
||||
from orm.author import Author
|
||||
from orm.shout import ShoutAuthor, ShoutTopic
|
||||
from orm.topic import Topic
|
||||
from resolvers.stat import get_with_stat
|
||||
from services.auth import login_required
|
||||
from cache.cache import (
|
||||
cache_author,
|
||||
get_cached_author,
|
||||
@@ -16,9 +11,14 @@ from cache.cache import (
|
||||
get_cached_follower_authors,
|
||||
get_cached_follower_topics,
|
||||
)
|
||||
from orm.author import Author
|
||||
from orm.shout import ShoutAuthor, ShoutTopic
|
||||
from orm.topic import Topic
|
||||
from resolvers.stat import get_with_stat
|
||||
from services.auth import login_required
|
||||
from services.db import local_session
|
||||
from utils.logger import root_logger as logger
|
||||
from services.schema import mutation, query
|
||||
from utils.logger import root_logger as logger
|
||||
|
||||
|
||||
@mutation.field("update_author")
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import time
|
||||
from sqlalchemy import and_, case, desc, func, select, asc
|
||||
|
||||
from sqlalchemy import and_, asc, case, desc, func, select
|
||||
from sqlalchemy.orm import aliased
|
||||
|
||||
from orm.author import Author
|
||||
@@ -11,9 +12,9 @@ from resolvers.follower import follow
|
||||
from resolvers.stat import update_author_stat
|
||||
from services.auth import add_user_role, login_required
|
||||
from services.db import local_session
|
||||
from utils.logger import root_logger as logger
|
||||
from services.notify import notify_reaction
|
||||
from services.schema import mutation, query
|
||||
from utils.logger import root_logger as logger
|
||||
|
||||
|
||||
def query_reactions():
|
||||
|
@@ -280,35 +280,39 @@ async def get_shout(_, info, slug: str):
|
||||
"""
|
||||
try:
|
||||
with local_session() as session:
|
||||
q, aliased_reaction = query_shouts(slug)
|
||||
results = session.execute(q).first()
|
||||
if results:
|
||||
[
|
||||
shout,
|
||||
commented_stat,
|
||||
followers_stat,
|
||||
rating_stat,
|
||||
last_reaction_at,
|
||||
authors,
|
||||
topics,
|
||||
main_topic_slug,
|
||||
] = results
|
||||
# Отключение автосохранения
|
||||
with session.no_autoflush:
|
||||
q, aliased_reaction = query_shouts(slug)
|
||||
results = session.execute(q).first()
|
||||
if results:
|
||||
[
|
||||
shout,
|
||||
commented_stat,
|
||||
followers_stat,
|
||||
rating_stat,
|
||||
last_reaction_at,
|
||||
authors,
|
||||
topics,
|
||||
main_topic_slug,
|
||||
] = results
|
||||
|
||||
shout.stat = {
|
||||
"viewed": ViewedStorage.get_shout(shout.id),
|
||||
"commented": commented_stat,
|
||||
"rating": rating_stat,
|
||||
"last_reacted_at": last_reaction_at,
|
||||
}
|
||||
# Используем класс модели Author для преобразования строк в объекты
|
||||
shout.authors = parse_aggregated_string(authors, Author)
|
||||
# Используем класс модели Topic для преобразования строк в объекты
|
||||
shout.topics = parse_aggregated_string(topics, Topic)
|
||||
shout.stat = {
|
||||
"viewed": ViewedStorage.get_shout(shout.id),
|
||||
"commented": commented_stat,
|
||||
"rating": rating_stat,
|
||||
"last_reacted_at": last_reaction_at,
|
||||
}
|
||||
|
||||
# Добавляем основной топик, если он существует
|
||||
shout.main_topic = main_topic_slug
|
||||
# Преобразование строк в объекты Author без их создания
|
||||
shout.authors = parse_aggregated_string(authors, Author)
|
||||
|
||||
return shout
|
||||
# Преобразование строк в объекты Topic без их создания
|
||||
shout.topics = parse_aggregated_string(topics, Topic)
|
||||
|
||||
# Добавляем основной топик, если он существует
|
||||
shout.main_topic = main_topic_slug
|
||||
|
||||
return shout
|
||||
except Exception as _exc:
|
||||
import traceback
|
||||
|
||||
|
@@ -3,11 +3,11 @@ import asyncio
|
||||
from sqlalchemy import and_, distinct, func, join, select
|
||||
from sqlalchemy.orm import aliased
|
||||
|
||||
from cache.cache import cache_author
|
||||
from orm.author import Author, AuthorFollower
|
||||
from orm.reaction import Reaction, ReactionKind
|
||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
||||
from orm.topic import Topic, TopicFollower
|
||||
from cache.cache import cache_author
|
||||
from services.db import local_session
|
||||
from utils.logger import root_logger as logger
|
||||
|
||||
|
@@ -1,15 +1,19 @@
|
||||
from sqlalchemy import distinct, func, select
|
||||
|
||||
from cache.cache import (
|
||||
get_cached_topic_authors,
|
||||
get_cached_topic_by_slug,
|
||||
get_cached_topic_followers,
|
||||
)
|
||||
from cache.memorycache import cache_region
|
||||
from orm.author import Author
|
||||
from orm.shout import ShoutTopic
|
||||
from orm.topic import Topic
|
||||
from resolvers.stat import get_with_stat
|
||||
from services.auth import login_required
|
||||
from cache.cache import get_cached_topic_authors, get_cached_topic_by_slug, get_cached_topic_followers
|
||||
from services.db import local_session
|
||||
from utils.logger import root_logger as logger
|
||||
from cache.memorycache import cache_region
|
||||
from services.schema import mutation, query
|
||||
from utils.logger import root_logger as logger
|
||||
|
||||
|
||||
# Запрос на получение всех тем
|
||||
|
Reference in New Issue
Block a user