From c15298143ffda60abd031a4ae9c670c844ff4982 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Wed, 14 Sep 2022 11:27:44 +0300 Subject: [PATCH] karma top --- migration/tables/content_items.py | 10 ++++------ resolvers/profile.py | 7 +++++++ schema.graphql | 1 + services/auth/users.py | 8 ++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/migration/tables/content_items.py b/migration/tables/content_items.py index ff27b211..461e0c5c 100644 --- a/migration/tables/content_items.py +++ b/migration/tables/content_items.py @@ -134,9 +134,8 @@ async def migrate(entry, storage): s = object() shout_dict = r.copy() user = None - del shout_dict[ - "topics" - ] # NOTE: AttributeError: 'str' object has no attribute '_sa_instance_state' + del shout_dict["topics"] + # NOTE: AttributeError: 'str' object has no attribute '_sa_instance_state' # del shout_dict['rating'] # NOTE: TypeError: 'rating' is an invalid keyword argument for Shout # del shout_dict['ratings'] email = userdata.get("email") @@ -160,10 +159,9 @@ async def migrate(entry, storage): storage["users"]["by_slug"][userdata["slug"]] = userdata storage["users"]["by_oid"][entry["_id"]] = userdata assert user, "could not get a user" - shout_dict["authors"] = [ - user, - ] + shout_dict["authors"] = [user, ] + # TODO: subscribe shout user on shout topics try: s = Shout.create(**shout_dict) except sqlalchemy.exc.IntegrityError as e: diff --git a/resolvers/profile.py b/resolvers/profile.py index d5df7848..48aa7434 100644 --- a/resolvers/profile.py +++ b/resolvers/profile.py @@ -187,3 +187,10 @@ def get_authors_all(_, info, page, size): end = page * size start = end - size return list(UserStorage.get_all_users())[start:end] # type: ignore + + +@query.field("topAuthors") +def get_top_authors(_, info, page, size): + end = page * size + start = end - size + return list(UserStorage.get_top_users())[start:end] # type: ignore diff --git a/schema.graphql b/schema.graphql index f214c8de..f136edec 100644 --- a/schema.graphql +++ b/schema.graphql @@ -234,6 +234,7 @@ type Query { myCandidates(page: Int!, size: Int!): [Shout]! # test topViewed(page: Int!, size: Int!): [Shout]! # topReacted(page: Int!, size: Int!): [Shout]! + topAuthors(page: Int!, size: Int!): [Author]! topMonth(page: Int!, size: Int!): [Shout]! topOverall(page: Int!, size: Int!): [Shout]! recentPublished(page: Int!, size: Int!): [Shout]! # homepage diff --git a/services/auth/users.py b/services/auth/users.py index 183b603a..dad50043 100644 --- a/services/auth/users.py +++ b/services/auth/users.py @@ -32,6 +32,14 @@ class UserStorage: aaa.sort(key=lambda user: user.createdAt) return aaa + @staticmethod + async def get_top_users(): + self = UserStorage + async with self.lock: + aaa = list(self.users.values()) + aaa.sort(key=lambda user: user.rating) + return aaa + @staticmethod async def get_user_by_slug(slug): self = UserStorage