This commit is contained in:
parent
8708efece2
commit
b2fdc9a453
|
@ -114,8 +114,7 @@ async def load_authors_by(_, _info, by, limit, offset):
|
||||||
authors_query = authors_query.filter(Author.name.ilike(f"%{by['name']}%"))
|
authors_query = authors_query.filter(Author.name.ilike(f"%{by['name']}%"))
|
||||||
elif by.get("topic"):
|
elif by.get("topic"):
|
||||||
authors_query = (
|
authors_query = (
|
||||||
authors_query
|
authors_query.join(ShoutAuthor) # Первое соединение ShoutAuthor
|
||||||
.join(ShoutAuthor) # Первое соединение ShoutAuthor
|
|
||||||
.join(ShoutTopic, ShoutAuthor.shout == ShoutTopic.shout)
|
.join(ShoutTopic, ShoutAuthor.shout == ShoutTopic.shout)
|
||||||
.join(Topic, ShoutTopic.topic == Topic.id)
|
.join(Topic, ShoutTopic.topic == Topic.id)
|
||||||
.filter(Topic.slug == str(by["topic"]))
|
.filter(Topic.slug == str(by["topic"]))
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
from sqlalchemy import distinct, func, select
|
from sqlalchemy import select
|
||||||
|
|
||||||
from orm.author import Author
|
from orm.author import Author
|
||||||
from orm.community import Community
|
from orm.community import Community
|
||||||
from orm.shout import ShoutCommunity
|
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
from services.schema import query
|
from services.schema import query
|
||||||
|
|
||||||
|
@ -12,11 +11,9 @@ def get_communities_from_query(q):
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
for [c, shouts_stat, followers_stat] in session.execute(q):
|
for [c, shouts_stat, followers_stat] in session.execute(q):
|
||||||
c.stat = {
|
c.stat = {
|
||||||
"shouts": session.execute(
|
"shouts": shouts_stat,
|
||||||
select(func.count(distinct(ShoutCommunity.shout))).filter(ShoutCommunity.community == c.id)
|
"followers": followers_stat,
|
||||||
),
|
|
||||||
# "authors": session.execute(select(func.count(distinct(ShoutCommunity.shout))).filter(ShoutCommunity.community == c.id)),
|
# "authors": session.execute(select(func.count(distinct(ShoutCommunity.shout))).filter(ShoutCommunity.community == c.id)),
|
||||||
# "followers": session.execute(select(func.count(distinct(ShoutCommunity.shout))).filter(ShoutCommunity.community == c.id)),
|
|
||||||
# "commented": commented_stat,
|
# "commented": commented_stat,
|
||||||
}
|
}
|
||||||
ccc.append(c)
|
ccc.append(c)
|
||||||
|
|
|
@ -34,7 +34,7 @@ async def handle_topic_follower_change(topic_id: int, follower_id: int, is_inser
|
||||||
topic = get_with_stat(topic_query)
|
topic = get_with_stat(topic_query)
|
||||||
follower_query = select(Author).filter(Author.id == follower_id)
|
follower_query = select(Author).filter(Author.id == follower_id)
|
||||||
follower = get_with_stat(follower_query)
|
follower = get_with_stat(follower_query)
|
||||||
if isinstance(follower[0],Author) and isinstance(topic[0], Topic):
|
if isinstance(follower[0], Author) and isinstance(topic[0], Topic):
|
||||||
topic = topic[0]
|
topic = topic[0]
|
||||||
follower = follower[0]
|
follower = follower[0]
|
||||||
await cache_topic(topic.dict())
|
await cache_topic(topic.dict())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user