This commit is contained in:
parent
ee577c75fd
commit
4cde1c14b4
|
@ -3,7 +3,6 @@ from sqlalchemy import event, select
|
|||
from services.rediscache import redis
|
||||
from orm.author import Author, AuthorFollower
|
||||
from orm.topic import Topic, TopicFollower
|
||||
from orm.shout import Shout, ShoutReactionsFollower
|
||||
|
||||
|
||||
@event.listens_for(Author, "after_insert")
|
||||
|
@ -20,7 +19,7 @@ async def update_follows_for_user(connection, user_id, entity_type, entity, is_i
|
|||
follows = {
|
||||
"topics": [],
|
||||
"authors": [],
|
||||
"shouts": [],
|
||||
# "shouts": [],
|
||||
"communities": [
|
||||
{"slug": "discours", "name": "Дискурс", "id": 1, "desc": ""}
|
||||
],
|
||||
|
@ -48,17 +47,6 @@ async def handle_author_follower_change(connection, author_id, follower_id, is_i
|
|||
)
|
||||
|
||||
|
||||
async def handle_shout_follower_change(connection, shout_id, follower_id, is_insert):
|
||||
shout = connection.execute(select(Topic).filter(Shout.id == shout_id)).first()
|
||||
follower = connection.execute(
|
||||
select(Author).filter(Author.id == follower_id)
|
||||
).first()
|
||||
if follower and shout:
|
||||
await update_follows_for_user(
|
||||
connection, follower.user, "shout", shout, is_insert
|
||||
)
|
||||
|
||||
|
||||
async def handle_topic_follower_change(connection, topic_id, follower_id, is_insert):
|
||||
topic = connection.execute(select(Topic).filter(Topic.id == topic_id)).first()
|
||||
follower = connection.execute(
|
||||
|
@ -80,16 +68,6 @@ async def after_topic_follower_delete(mapper, connection, target):
|
|||
await handle_topic_follower_change(connection, target.topic, target.follower, False)
|
||||
|
||||
|
||||
@event.listens_for(ShoutReactionsFollower, "after_insert")
|
||||
async def after_shout_follower_insert(mapper, connection, target):
|
||||
await handle_shout_follower_change(connection, target.shout, target.follower, True)
|
||||
|
||||
|
||||
@event.listens_for(ShoutReactionsFollower, "after_delete")
|
||||
async def after_shout_follower_delete(mapper, connection, target):
|
||||
await handle_shout_follower_change(connection, target.shout, target.follower, False)
|
||||
|
||||
|
||||
@event.listens_for(AuthorFollower, "after_insert")
|
||||
async def after_author_follower_insert(mapper, connection, target):
|
||||
await handle_author_follower_change(
|
||||
|
|
|
@ -9,7 +9,13 @@ from resolvers.author import (
|
|||
)
|
||||
from resolvers.community import get_communities_all, get_community
|
||||
from resolvers.editor import create_shout, delete_shout, update_shout
|
||||
from resolvers.follower import follow, unfollow, get_topic_followers, get_shout_followers, get_author_followers
|
||||
from resolvers.follower import (
|
||||
follow,
|
||||
unfollow,
|
||||
get_topic_followers,
|
||||
get_shout_followers,
|
||||
get_author_followers,
|
||||
)
|
||||
from resolvers.reaction import (
|
||||
create_reaction,
|
||||
delete_reaction,
|
||||
|
|
|
@ -5,13 +5,19 @@ from sqlalchemy.orm import aliased
|
|||
from sqlalchemy.sql import and_
|
||||
|
||||
from orm.author import Author, AuthorFollower
|
||||
from orm.community import Community
|
||||
|
||||
# from orm.community import Community
|
||||
from orm.reaction import Reaction
|
||||
from orm.shout import Shout, ShoutReactionsFollower
|
||||
from orm.topic import Topic, TopicFollower
|
||||
from resolvers.author import add_author_stat_columns, get_authors_from_query
|
||||
from resolvers.community import community_follow, community_unfollow
|
||||
from resolvers.topic import topic_follow, topic_unfollow, add_topic_stat_columns, get_topics_from_query
|
||||
from resolvers.topic import (
|
||||
topic_follow,
|
||||
topic_unfollow,
|
||||
add_topic_stat_columns,
|
||||
get_topics_from_query,
|
||||
)
|
||||
from services.auth import login_required
|
||||
from services.db import local_session
|
||||
from services.notify import notify_follower
|
||||
|
@ -85,7 +91,7 @@ async def unfollow(_, info, what, slug):
|
|||
def query_follows(user_id: str):
|
||||
topics = set()
|
||||
authors = set()
|
||||
communities = []
|
||||
# communities = []
|
||||
with local_session() as session:
|
||||
author = session.query(Author).filter(Author.user == user_id).first()
|
||||
if isinstance(author, Author):
|
||||
|
@ -103,22 +109,23 @@ def query_follows(user_id: str):
|
|||
.filter(TopicFollower.topic == Topic.id)
|
||||
)
|
||||
|
||||
shouts_query = (
|
||||
session.query(Shout, ShoutReactionsFollower)
|
||||
.join(ShoutReactionsFollower, ShoutReactionsFollower.follower == author_id)
|
||||
.filter(ShoutReactionsFollower.shout == Shout.id)
|
||||
)
|
||||
# NOTE: this loads separated paginating query
|
||||
# shouts_query = (
|
||||
# session.query(Shout, ShoutReactionsFollower)
|
||||
# .join(ShoutReactionsFollower, ShoutReactionsFollower.follower == author_id)
|
||||
# .filter(ShoutReactionsFollower.shout == Shout.id)
|
||||
# )
|
||||
|
||||
authors = set(session.execute(authors_query).scalars())
|
||||
topics = set(session.execute(topics_query).scalars())
|
||||
shouts = set(session.execute(shouts_query).scalars())
|
||||
communities = session.query(Community).all()
|
||||
# shouts = set(session.execute(shouts_query).scalars())
|
||||
# communities = session.query(Community).all()
|
||||
|
||||
return {
|
||||
"topics": list(topics),
|
||||
"authors": list(authors),
|
||||
"shouts": list(shouts),
|
||||
"communities": communities,
|
||||
# "shouts": list(shouts),
|
||||
"communities": {"id": 1, "name": "Дискурс", "slug": "discours"},
|
||||
}
|
||||
|
||||
|
||||
|
@ -248,7 +255,7 @@ async def get_author_followers(_, _info, slug) -> List[Author]:
|
|||
|
||||
@query.field("get_shout_followers")
|
||||
def get_shout_followers(
|
||||
_, _info, slug: str = "", shout_id: int | None = None
|
||||
_, _info, slug: str = "", shout_id: int | None = None
|
||||
) -> List[Author]:
|
||||
followers = []
|
||||
with local_session() as session:
|
||||
|
|
|
@ -17,13 +17,13 @@ type Query {
|
|||
get_topic_followers(slug: String, topic_id: Int): [Author]
|
||||
get_author_followers(slug: String, user: String, author_id: Int): [Author]
|
||||
get_author_follows(slug: String, user: String, author_id: Int): AuthorFollows!
|
||||
load_shouts_followed(follower_id: Int!, limit: Int, offset: Int): [Shout] # userReactedShouts
|
||||
|
||||
# reaction
|
||||
load_reactions_by(by: ReactionBy!, limit: Int, offset: Int): [Reaction]
|
||||
|
||||
# reader
|
||||
get_shout(slug: String, shout_id: Int): Shout
|
||||
load_shouts_followed(follower_id: Int!, limit: Int, offset: Int): [Shout] # userReactedShouts
|
||||
load_shouts_by(options: LoadShoutsOptions): [Shout]
|
||||
load_shouts_search(text: String!, limit: Int, offset: Int): [SearchResult]
|
||||
load_shouts_feed(options: LoadShoutsOptions): [Shout]
|
||||
|
|
|
@ -183,6 +183,6 @@ type Invite {
|
|||
type AuthorFollows {
|
||||
topics: [Topic]
|
||||
authors: [Author]
|
||||
shouts: [Shout]
|
||||
# shouts: [Shout]
|
||||
communities: [Community]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user