This commit is contained in:
parent
5dbb0ccb12
commit
0b185c1c2d
|
@ -1,24 +1,52 @@
|
||||||
from resolvers.author import (get_author, get_author_followers,
|
from resolvers.author import (
|
||||||
get_author_follows, get_author_follows_authors,
|
get_author,
|
||||||
get_author_follows_topics, get_author_id,
|
get_author_followers,
|
||||||
get_authors_all, load_authors_by, search_authors,
|
get_author_follows,
|
||||||
update_author)
|
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.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,
|
from resolvers.follower import (
|
||||||
get_topic_followers, unfollow)
|
follow,
|
||||||
from resolvers.notifier import (load_notifications, notification_mark_seen,
|
get_shout_followers,
|
||||||
|
get_topic_followers,
|
||||||
|
unfollow,
|
||||||
|
)
|
||||||
|
from resolvers.notifier import (
|
||||||
|
load_notifications,
|
||||||
|
notification_mark_seen,
|
||||||
notifications_seen_after,
|
notifications_seen_after,
|
||||||
notifications_seen_thread)
|
notifications_seen_thread,
|
||||||
|
)
|
||||||
from resolvers.rating import rate_author
|
from resolvers.rating import rate_author
|
||||||
from resolvers.reaction import (create_reaction, delete_reaction,
|
from resolvers.reaction import (
|
||||||
load_reactions_by, load_shouts_followed,
|
create_reaction,
|
||||||
update_reaction)
|
delete_reaction,
|
||||||
from resolvers.reader import (get_shout, load_shouts_by, load_shouts_feed,
|
load_reactions_by,
|
||||||
load_shouts_random_top, load_shouts_random_topic,
|
load_shouts_followed,
|
||||||
load_shouts_search, load_shouts_unrated)
|
update_reaction,
|
||||||
from resolvers.topic import (get_topic, get_topics_all, get_topics_by_author,
|
)
|
||||||
get_topics_by_community)
|
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
|
from services.triggers import events_register
|
||||||
|
|
||||||
events_register()
|
events_register()
|
||||||
|
|
|
@ -8,8 +8,7 @@ from sqlalchemy_searchable import search
|
||||||
from orm.author import Author, AuthorFollower
|
from orm.author import Author, AuthorFollower
|
||||||
from orm.shout import ShoutAuthor, ShoutTopic
|
from orm.shout import ShoutAuthor, ShoutTopic
|
||||||
from orm.topic import Topic
|
from orm.topic import Topic
|
||||||
from resolvers.stat import (author_follows_authors, author_follows_topics,
|
from resolvers.stat import author_follows_authors, author_follows_topics, get_with_stat
|
||||||
get_with_stat)
|
|
||||||
from services.auth import login_required
|
from services.auth import login_required
|
||||||
from services.cache import cache_author, cache_follower
|
from services.cache import cache_author, cache_follower
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
|
|
|
@ -11,8 +11,7 @@ from orm.community import Community
|
||||||
from orm.reaction import Reaction
|
from orm.reaction import Reaction
|
||||||
from orm.shout import Shout, ShoutReactionsFollower
|
from orm.shout import Shout, ShoutReactionsFollower
|
||||||
from orm.topic import Topic, TopicFollower
|
from orm.topic import Topic, TopicFollower
|
||||||
from resolvers.stat import (author_follows_authors, author_follows_topics,
|
from resolvers.stat import author_follows_authors, author_follows_topics, get_with_stat
|
||||||
get_with_stat)
|
|
||||||
from services.auth import login_required
|
from services.auth import login_required
|
||||||
from services.cache import DEFAULT_FOLLOWS, cache_follower
|
from services.cache import DEFAULT_FOLLOWS, cache_follower
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
|
|
|
@ -8,8 +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,
|
from orm.notification import (
|
||||||
NotificationEntity, NotificationSeen)
|
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
|
||||||
|
|
|
@ -6,8 +6,7 @@ from sqlalchemy.orm import aliased, joinedload
|
||||||
from sqlalchemy.sql import union
|
from sqlalchemy.sql import union
|
||||||
|
|
||||||
from orm.author import Author
|
from orm.author import Author
|
||||||
from orm.rating import (PROPOSAL_REACTIONS, RATING_REACTIONS, is_negative,
|
from orm.rating import PROPOSAL_REACTIONS, RATING_REACTIONS, is_negative, is_positive
|
||||||
is_positive)
|
|
||||||
from orm.reaction import Reaction, ReactionKind
|
from orm.reaction import Reaction, ReactionKind
|
||||||
from orm.shout import Shout
|
from orm.shout import Shout
|
||||||
from resolvers.editor import handle_proposing
|
from resolvers.editor import handle_proposing
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from sqlalchemy import bindparam, distinct, or_, text
|
from sqlalchemy import bindparam, distinct, or_, text
|
||||||
from sqlalchemy.orm import aliased, joinedload
|
from sqlalchemy.orm import aliased, joinedload
|
||||||
from sqlalchemy.sql.expression import (and_, asc, case, desc, func, nulls_last,
|
from sqlalchemy.sql.expression import and_, asc, case, desc, func, nulls_last, select
|
||||||
select)
|
|
||||||
|
|
||||||
from orm.author import Author, AuthorFollower
|
from orm.author import Author, AuthorFollower
|
||||||
from orm.reaction import Reaction, ReactionKind
|
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")
|
func.count(distinct(aliased_shout.shout)).label("shouts_stat")
|
||||||
)
|
)
|
||||||
aliased_follower = aliased(TopicFollower)
|
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(
|
).add_columns(
|
||||||
func.count(distinct(aliased_follower.follower)).label("followers_stat")
|
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")
|
func.count(distinct(aliased_shout.shout)).label("shouts_stat")
|
||||||
)
|
)
|
||||||
aliased_follower = aliased(AuthorFollower)
|
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(
|
).add_columns(
|
||||||
func.count(distinct(aliased_follower.follower)).label("followers_stat")
|
func.count(distinct(aliased_follower.follower)).label("followers_stat")
|
||||||
)
|
)
|
||||||
|
@ -41,6 +43,7 @@ def add_author_stat_columns(q):
|
||||||
|
|
||||||
return q
|
return q
|
||||||
|
|
||||||
|
|
||||||
def get_topic_shouts_stat(topic_id: int):
|
def get_topic_shouts_stat(topic_id: int):
|
||||||
q = (
|
q = (
|
||||||
select(func.count(distinct(ShoutTopic.shout)))
|
select(func.count(distinct(ShoutTopic.shout)))
|
||||||
|
@ -174,7 +177,9 @@ def get_with_stat(q):
|
||||||
is_author = f"{q}".lower().startswith("select author")
|
is_author = f"{q}".lower().startswith("select author")
|
||||||
# is_topic = f"{q}".lower().startswith("select topic")
|
# is_topic = f"{q}".lower().startswith("select topic")
|
||||||
result = []
|
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:
|
with local_session() as session:
|
||||||
result = session.execute(add_stat_handler(q))
|
result = session.execute(add_stat_handler(q))
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,7 @@ import traceback
|
||||||
import warnings
|
import warnings
|
||||||
from typing import Any, Callable, Dict, TypeVar
|
from typing import Any, Callable, Dict, TypeVar
|
||||||
|
|
||||||
from sqlalchemy import (JSON, Column, Engine, Integer, create_engine, event,
|
from sqlalchemy import JSON, Column, Engine, Integer, create_engine, event, exc, inspect
|
||||||
exc, inspect)
|
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import Session, configure_mappers
|
from sqlalchemy.orm import Session, configure_mappers
|
||||||
from sqlalchemy.sql.schema import Table
|
from sqlalchemy.sql.schema import Table
|
||||||
|
|
|
@ -7,8 +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,
|
from google.analytics.data_v1beta.types import (
|
||||||
RunReportRequest)
|
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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user