karma top
This commit is contained in:
parent
80a1aeb767
commit
c15298143f
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user