This commit is contained in:
parent
5dbb0ccb12
commit
0b185c1c2d
|
@ -1,24 +1,52 @@
|
|||
from resolvers.author import (get_author, get_author_followers,
|
||||
get_author_follows, get_author_follows_authors,
|
||||
get_author_follows_topics, get_author_id,
|
||||
get_authors_all, load_authors_by, search_authors,
|
||||
update_author)
|
||||
from resolvers.author import (
|
||||
get_author,
|
||||
get_author_followers,
|
||||
get_author_follows,
|
||||
get_author_follows_authors,
|
||||
get_author_follows_topics,
|
||||
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.notifier import (load_notifications, notification_mark_seen,
|
||||
notifications_seen_after,
|
||||
notifications_seen_thread)
|
||||
from resolvers.follower import (
|
||||
follow,
|
||||
get_shout_followers,
|
||||
get_topic_followers,
|
||||
unfollow,
|
||||
)
|
||||
from resolvers.notifier import (
|
||||
load_notifications,
|
||||
notification_mark_seen,
|
||||
notifications_seen_after,
|
||||
notifications_seen_thread,
|
||||
)
|
||||
from resolvers.rating import rate_author
|
||||
from resolvers.reaction import (create_reaction, delete_reaction,
|
||||
load_reactions_by, load_shouts_followed,
|
||||
update_reaction)
|
||||
from resolvers.reader import (get_shout, load_shouts_by, load_shouts_feed,
|
||||
load_shouts_random_top, load_shouts_random_topic,
|
||||
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.reaction import (
|
||||
create_reaction,
|
||||
delete_reaction,
|
||||
load_reactions_by,
|
||||
load_shouts_followed,
|
||||
update_reaction,
|
||||
)
|
||||
from resolvers.reader import (
|
||||
get_shout,
|
||||
load_shouts_by,
|
||||
load_shouts_feed,
|
||||
load_shouts_random_top,
|
||||
load_shouts_random_topic,
|
||||
load_shouts_search,
|
||||
load_shouts_unrated,
|
||||
)
|
||||
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()
|
||||
|
|
|
@ -8,8 +8,7 @@ from sqlalchemy_searchable import search
|
|||
from orm.author import Author, AuthorFollower
|
||||
from orm.shout import ShoutAuthor, ShoutTopic
|
||||
from orm.topic import Topic
|
||||
from resolvers.stat import (author_follows_authors, author_follows_topics,
|
||||
get_with_stat)
|
||||
from resolvers.stat import author_follows_authors, author_follows_topics, get_with_stat
|
||||
from services.auth import login_required
|
||||
from services.cache import cache_author, cache_follower
|
||||
from services.db import local_session
|
||||
|
|
|
@ -11,8 +11,7 @@ from orm.community import Community
|
|||
from orm.reaction import Reaction
|
||||
from orm.shout import Shout, ShoutReactionsFollower
|
||||
from orm.topic import Topic, TopicFollower
|
||||
from resolvers.stat import (author_follows_authors, author_follows_topics,
|
||||
get_with_stat)
|
||||
from resolvers.stat import author_follows_authors, author_follows_topics, get_with_stat
|
||||
from services.auth import login_required
|
||||
from services.cache import DEFAULT_FOLLOWS, cache_follower
|
||||
from services.db import local_session
|
||||
|
|
|
@ -8,8 +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
|
||||
|
|
|
@ -6,8 +6,7 @@ from sqlalchemy.orm import aliased, joinedload
|
|||
from sqlalchemy.sql import union
|
||||
|
||||
from orm.author import Author
|
||||
from orm.rating import (PROPOSAL_REACTIONS, RATING_REACTIONS, is_negative,
|
||||
is_positive)
|
||||
from orm.rating import PROPOSAL_REACTIONS, RATING_REACTIONS, is_negative, is_positive
|
||||
from orm.reaction import Reaction, ReactionKind
|
||||
from orm.shout import Shout
|
||||
from resolvers.editor import handle_proposing
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from sqlalchemy import bindparam, distinct, or_, text
|
||||
from sqlalchemy.orm import aliased, joinedload
|
||||
from sqlalchemy.sql.expression import (and_, asc, case, desc, func, nulls_last,
|
||||
select)
|
||||
from sqlalchemy.sql.expression import and_, asc, case, desc, func, nulls_last, select
|
||||
|
||||
from orm.author import Author, AuthorFollower
|
||||
from orm.reaction import Reaction, ReactionKind
|
||||
|
|
|
@ -16,7 +16,8 @@ def add_topic_stat_columns(q):
|
|||
func.count(distinct(aliased_shout.shout)).label("shouts_stat")
|
||||
)
|
||||
aliased_follower = aliased(TopicFollower)
|
||||
q = q.outerjoin(aliased_follower, aliased_follower.follower == Author.id
|
||||
q = q.outerjoin(
|
||||
aliased_follower, aliased_follower.follower == Author.id
|
||||
).add_columns(
|
||||
func.count(distinct(aliased_follower.follower)).label("followers_stat")
|
||||
)
|
||||
|
@ -32,7 +33,8 @@ def add_author_stat_columns(q):
|
|||
func.count(distinct(aliased_shout.shout)).label("shouts_stat")
|
||||
)
|
||||
aliased_follower = aliased(AuthorFollower)
|
||||
q = q.outerjoin(aliased_follower, aliased_follower.follower == Author.id
|
||||
q = q.outerjoin(
|
||||
aliased_follower, aliased_follower.follower == Author.id
|
||||
).add_columns(
|
||||
func.count(distinct(aliased_follower.follower)).label("followers_stat")
|
||||
)
|
||||
|
@ -41,6 +43,7 @@ def add_author_stat_columns(q):
|
|||
|
||||
return q
|
||||
|
||||
|
||||
def get_topic_shouts_stat(topic_id: int):
|
||||
q = (
|
||||
select(func.count(distinct(ShoutTopic.shout)))
|
||||
|
@ -150,7 +153,7 @@ def get_author_comments_stat(author_id: int):
|
|||
select(
|
||||
Author.id, func.coalesce(func.count(Reaction.id)).label("comments_count")
|
||||
)
|
||||
.select_from(Author) # явно указываем левый элемент join'а
|
||||
.select_from(Author) # явно указываем левый элемент join'а
|
||||
.outerjoin(
|
||||
Reaction,
|
||||
and_(
|
||||
|
@ -174,7 +177,9 @@ 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
|
||||
add_stat_handler = (
|
||||
add_author_stat_columns if is_author else add_topic_stat_columns
|
||||
)
|
||||
with local_session() as session:
|
||||
result = session.execute(add_stat_handler(q))
|
||||
|
||||
|
|
|
@ -5,8 +5,7 @@ import traceback
|
|||
import warnings
|
||||
from typing import Any, Callable, Dict, TypeVar
|
||||
|
||||
from sqlalchemy import (JSON, Column, Engine, Integer, create_engine, event,
|
||||
exc, inspect)
|
||||
from sqlalchemy import JSON, Column, Engine, Integer, create_engine, event, exc, inspect
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import Session, configure_mappers
|
||||
from sqlalchemy.sql.schema import Table
|
||||
|
|
|
@ -7,8 +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
|
||||
|
|
Loading…
Reference in New Issue
Block a user