From 2102242da970271a0100a9615e3d5387e42f8449 Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Sun, 1 Oct 2023 19:15:45 +0200 Subject: [PATCH 1/7] bio/about fix --- migration/tables/users.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/migration/tables/users.py b/migration/tables/users.py index 4e34b7eb..b23244ed 100644 --- a/migration/tables/users.py +++ b/migration/tables/users.py @@ -37,11 +37,7 @@ def migrate(entry): slug = re.sub('[^0-9a-zA-Z]+', '-', slug).strip() user_dict["slug"] = slug bio = (entry.get("profile", {"bio": ""}).get("bio") or "").replace('\(', '(').replace('\)', ')') - bio_html = BeautifulSoup(bio, features="lxml").text - if bio == bio_html: - user_dict["bio"] = bio - else: - user_dict["about"] = bio + user_dict["about"] = bio # userpic try: From 36778748797f07316b7cc6a4014912cf0830ef99 Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Sun, 1 Oct 2023 19:27:08 +0200 Subject: [PATCH 2/7] excludeLayout filter for loadShouts --- resolvers/zine/load.py | 8 +++++++- schema.graphql | 15 +-------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/resolvers/zine/load.py b/resolvers/zine/load.py index 7b36c5b6..3f91b92d 100644 --- a/resolvers/zine/load.py +++ b/resolvers/zine/load.py @@ -60,6 +60,8 @@ def apply_filters(q, filters, user_id=None): if filters.get("layout"): q = q.filter(Shout.layout == filters.get("layout")) + if filters.get('excludeLayout'): + q = q.filter(Shout.layout != filters.get("excludeLayout")) if filters.get("author"): q = q.filter(Shout.authors.any(slug=filters.get("author"))) if filters.get("topic"): @@ -123,6 +125,7 @@ async def load_shouts_by(_, info, options): :param options: { filters: { layout: 'audio', + excludeLayout: 'article', visibility: "public", author: 'discours', topic: 'culture', @@ -143,7 +146,10 @@ async def load_shouts_by(_, info, options): joinedload(Shout.authors), joinedload(Shout.topics), ).where( - Shout.deletedAt.is_(None) + and_( + Shout.deletedAt.is_(None), + Shout.layout.is_not(None) + ) ) q = add_stat_columns(q) diff --git a/schema.graphql b/schema.graphql index 70dfa8e7..7aff3eaf 100644 --- a/schema.graphql +++ b/schema.graphql @@ -217,26 +217,13 @@ input AuthorsBy { stat: String } -input ShoutsFilterBy { - slug: String - title: String - body: String - topic: String - topics: [String] - author: String - authors: [String] - layout: String - visibility: String - days: Int - stat: String -} - input LoadShoutsFilters { title: String body: String topic: String author: String layout: String + excludeLayout: String visibility: String days: Int reacted: Boolean From 2df74a9dd84670845b3bddcab521af8da88da09a Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Mon, 2 Oct 2023 17:35:29 +0200 Subject: [PATCH 3/7] user registration date added to graphql schema --- schema.graphql | 1 + 1 file changed, 1 insertion(+) diff --git a/schema.graphql b/schema.graphql index 7aff3eaf..86f6f8c6 100644 --- a/schema.graphql +++ b/schema.graphql @@ -56,6 +56,7 @@ type Author { stat: AuthorStat roles: [Role] # in different communities lastSeen: DateTime + createdAt: DateTime } type Result { From c3739f341f4b26cf252eb24bd0de8ac329ab18f0 Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Wed, 4 Oct 2023 19:49:17 +0200 Subject: [PATCH 4/7] https://trello.com/c/QxucY23H/314-%D0%BC%D0%B8%D0%B3%D1%80%D0%B0%D1%86%D0%B8%D1%8F-%D0%BA%D0%BB%D0%B0%D1%81%D1%82%D1%8C-%D1%81%D1%82%D0%B0%D1%80%D1%83%D1%8E-%D0%B8%D0%BD%D1%84%D1%83-%D0%BE-%D1%81%D0%B5%D0%B1%D0%B5-%D0%B2-%D0%BF%D0%BE%D0%BB%D0%B5-%D0%BE-%D1%81%D0%B5%D0%B1%D0%B5-%D0%B2-%D0%BF%D1%80%D0%B5%D0%B4%D1%81%D1%82%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D0%B8-%D1%8D%D1%82%D1%83-%D0%B8%D0%BD%D1%84%D1%83-%D0%B4%D0%BE%D0%B1%D0%B0%D0%B2%D0%BB%D1%8F%D0%B5%D0%BC-%D1%82%D0%BE%D0%BB%D1%8C%D0%BA%D0%BE-%D0%B5%D1%81%D0%BB%D0%B8-%D0%BE%D0%BD%D0%B0-%D0%BD%D0%B5-%D0%B1%D0%BE%D0%BB%D1%8C%D1%88%D0%B5-120-%D1%81%D0%B8%D0%BC%D0%B2%D0%BE%D0%BB%D0%BE%D0%B2 --- migration/tables/users.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/migration/tables/users.py b/migration/tables/users.py index b23244ed..e269da28 100644 --- a/migration/tables/users.py +++ b/migration/tables/users.py @@ -37,7 +37,10 @@ def migrate(entry): slug = re.sub('[^0-9a-zA-Z]+', '-', slug).strip() user_dict["slug"] = slug bio = (entry.get("profile", {"bio": ""}).get("bio") or "").replace('\(', '(').replace('\)', ')') - user_dict["about"] = bio + if len(bio) > 120: + user_dict["bio"] = bio + else: + user_dict["about"] = bio # userpic try: From 2a97bdb2d41adfb73d1999c7b50b6abddcaf4796 Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Wed, 4 Oct 2023 21:41:49 +0200 Subject: [PATCH 5/7] fixed html in bio/about --- migration/tables/users.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/migration/tables/users.py b/migration/tables/users.py index e269da28..dde3bca3 100644 --- a/migration/tables/users.py +++ b/migration/tables/users.py @@ -37,10 +37,12 @@ def migrate(entry): slug = re.sub('[^0-9a-zA-Z]+', '-', slug).strip() user_dict["slug"] = slug bio = (entry.get("profile", {"bio": ""}).get("bio") or "").replace('\(', '(').replace('\)', ')') - if len(bio) > 120: - user_dict["bio"] = bio + bio_text = BeautifulSoup(bio, features="lxml").text + + if len(bio_text) > 120: + user_dict["bio"] = bio_text else: - user_dict["about"] = bio + user_dict["about"] = bio_text # userpic try: From 2ae5a7b0bd254053fc66e717327ddddebd44394d Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Thu, 5 Oct 2023 11:41:22 +0200 Subject: [PATCH 6/7] another bio/about fix --- migration/tables/users.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migration/tables/users.py b/migration/tables/users.py index dde3bca3..d7a0f260 100644 --- a/migration/tables/users.py +++ b/migration/tables/users.py @@ -40,9 +40,9 @@ def migrate(entry): bio_text = BeautifulSoup(bio, features="lxml").text if len(bio_text) > 120: - user_dict["bio"] = bio_text - else: user_dict["about"] = bio_text + else: + user_dict["bio"] = bio_text # userpic try: From 2361f404f48ecd0ae583ab560c1b85c3a3d4bb4f Mon Sep 17 00:00:00 2001 From: Igor Lobanov Date: Thu, 5 Oct 2023 17:06:03 +0200 Subject: [PATCH 7/7] added heavy stat for getAuthor --- resolvers/zine/profile.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/resolvers/zine/profile.py b/resolvers/zine/profile.py index 98041b2c..2856553b 100644 --- a/resolvers/zine/profile.py +++ b/resolvers/zine/profile.py @@ -17,11 +17,10 @@ from resolvers.inbox.unread import get_total_unread_counter from resolvers.zine.topics import followed_by_user -def add_author_stat_columns(q): +def add_author_stat_columns(q, include_heavy_stat=False): author_followers = aliased(AuthorFollower) author_following = aliased(AuthorFollower) shout_author_aliased = aliased(ShoutAuthor) - # user_rating_aliased = aliased(UserRating) q = q.outerjoin(shout_author_aliased).add_columns( func.count(distinct(shout_author_aliased.shout)).label('shouts_stat') @@ -34,17 +33,26 @@ def add_author_stat_columns(q): func.count(distinct(author_following.author)).label('followings_stat') ) - q = q.add_columns(literal(0).label('rating_stat')) - # FIXME - # q = q.outerjoin(user_rating_aliased, user_rating_aliased.user == User.id).add_columns( - # # TODO: check - # func.sum(user_rating_aliased.value).label('rating_stat') - # ) + if include_heavy_stat: + user_rating_aliased = aliased(UserRating) + q = q.outerjoin(user_rating_aliased, user_rating_aliased.user == User.id).add_columns( + func.sum(user_rating_aliased.value).label('rating_stat') + ) - q = q.add_columns(literal(0).label('commented_stat')) - # q = q.outerjoin(Reaction, and_(Reaction.createdBy == User.id, Reaction.body.is_not(None))).add_columns( - # func.count(distinct(Reaction.id)).label('commented_stat') - # ) + else: + q = q.add_columns(literal(-1).label('rating_stat')) + + if include_heavy_stat: + q = q.outerjoin( + Reaction, + and_( + Reaction.createdBy == User.id, + Reaction.body.is_not(None) + )).add_columns( + func.count(distinct(Reaction.id)).label('commented_stat') + ) + else: + q = q.add_columns(literal(-1).label('commented_stat')) q = q.group_by(User.id) @@ -101,6 +109,7 @@ async def followed_reactions(user_id): Reaction.createdAt > user.lastSeen ).all() + # dufok mod (^*^') : @query.field("userFollowedTopics") async def get_followed_topics(_, info, slug) -> List[Topic]: @@ -117,6 +126,7 @@ async def get_followed_topics(_, info, slug) -> List[Topic]: async def followed_topics(user_id): return followed_by_user(user_id) + # dufok mod (^*^') : @query.field("userFollowedAuthors") async def get_followed_authors(_, _info, slug) -> List[User]: @@ -130,6 +140,7 @@ async def get_followed_authors(_, _info, slug) -> List[User]: return await followed_authors(user_id) + # 2. Now, we can use the user_id to get the followed authors async def followed_authors(user_id): q = select(User) @@ -255,7 +266,7 @@ async def get_authors_all(_, _info): @query.field("getAuthor") async def get_author(_, _info, slug): q = select(User).where(User.slug == slug) - q = add_author_stat_columns(q) + q = add_author_stat_columns(q, True) authors = get_authors_from_query(q) return authors[0]