recent_commented

This commit is contained in:
Tony 2022-02-03 12:13:53 +03:00
parent 6b255cc984
commit dd85d58ccf
2 changed files with 278 additions and 253 deletions

View File

@ -98,6 +98,24 @@ class ShoutsCache:
async with ShoutsCache.lock: async with ShoutsCache.lock:
ShoutsCache.recent_shouts = shouts ShoutsCache.recent_shouts = shouts
# TODO: DEBUG ME
@staticmethod
async def prepare_recent_commented():
with local_session() as session:
stmt = select(Shout).\
options(selectinload(Shout.authors), selectinload(Shout.topics)).\
join(Comment).\
where(and_(Shout.publishedAt != None, Comment.publishedAt == User.id)).\
order_by(desc("publishedAt")).\
limit(ShoutsCache.limit)
shouts = []
for row in session.execute(stmt):
shout = row.Shout
shout.ratings = await ShoutRatingStorage.get_ratings(shout.slug)
shouts.append(shout)
async with ShoutsCache.lock:
ShoutsCache.recent_shouts = shouts
@staticmethod @staticmethod
async def prepare_top_overall(): async def prepare_top_overall():
@ -166,6 +184,7 @@ class ShoutsCache:
await ShoutsCache.prepare_top_overall() await ShoutsCache.prepare_top_overall()
await ShoutsCache.prepare_top_viewed() await ShoutsCache.prepare_top_viewed()
await ShoutsCache.prepare_recent_shouts() await ShoutsCache.prepare_recent_shouts()
await ShoutsCache.prepare_recent_commented()
print("shouts cache update finished") print("shouts cache update finished")
except Exception as err: except Exception as err:
print("shouts cache worker error = %s" % (err)) print("shouts cache worker error = %s" % (err))
@ -211,6 +230,11 @@ async def recent_shouts(_, info, page, size):
async with ShoutsCache.lock: async with ShoutsCache.lock:
return ShoutsCache.recent_shouts[(page - 1) * size : page * size] return ShoutsCache.recent_shouts[(page - 1) * size : page * size]
@query.field("recentCommented")
async def recent_shouts(_, info, page, size):
async with ShoutsCache.lock:
return ShoutsCache.recent_commented[(page - 1) * size : page * size]
@mutation.field("createShout") @mutation.field("createShout")
@login_required @login_required
async def create_shout(_, info, input): async def create_shout(_, info, input):

View File

@ -3,398 +3,399 @@ scalar DateTime
################################### Payload ################################### Payload
type Result { type Result {
error: String error: String
} }
type AuthResult { type AuthResult {
error: String error: String
token: String token: String
user: User user: User
} }
type UserResult { type UserResult {
error: String error: String
user: User user: User
} }
type MessageResult { type MessageResult {
error: String error: String
message: Message message: Message
} }
input ShoutInput { input ShoutInput {
slug: String! slug: String!
body: String! body: String!
community: Int! community: Int!
mainTopic: String mainTopic: String
topic_slugs: [String] topic_slugs: [String]
title: String title: String
subtitle: String subtitle: String
versionOf: String versionOf: String
visibleForRoles: [String] # role ids are strings visibleForRoles: [String] # role ids are strings
visibleForUsers: [Int] visibleForUsers: [Int]
} }
input ProfileInput { input ProfileInput {
name: String name: String
userpic: String userpic: String
links: [String] links: [String]
bio: String bio: String
} }
input CommunityInput { input CommunityInput {
title: String! title: String!
desc: String desc: String
pic: String pic: String
} }
type ShoutResult { type ShoutResult {
error: String error: String
shout: Shout shout: Shout
} }
type CommentResult { type CommentResult {
error: String error: String
comment: Comment comment: Comment
} }
enum MessageStatus { enum MessageStatus {
NEW NEW
UPDATED UPDATED
DELETED DELETED
} }
type ChatUpdatedResult { type ChatUpdatedResult {
error: String error: String
status: MessageStatus status: MessageStatus
message: Message message: Message
} }
type CreateChatResult { type CreateChatResult {
chatId: String chatId: String
error: String error: String
} }
type EnterChatResult { type EnterChatResult {
chat: Chat chat: Chat
messages: [Message] messages: [Message]
error: String error: String
} }
input TopicInput { input TopicInput {
slug: String! slug: String!
title: String title: String
body: String body: String
pic: String pic: String
children: [String] children: [String]
community: String! community: String!
} }
type TopicResult { type TopicResult {
error: String error: String
topic: Topic topic: Topic
} }
enum CommentStatus { enum CommentStatus {
NEW NEW
UPDATED UPDATED
UPDATED_RATING UPDATED_RATING
DELETED DELETED
} }
type CommentUpdatedResult { type CommentUpdatedResult {
error: String error: String
status: CommentStatus status: CommentStatus
comment: Comment comment: Comment
} }
################################### Mutation ################################### Mutation
type Mutation { type Mutation {
# message # message
createChat(description: String): CreateChatResult! createChat(description: String): CreateChatResult!
createMessage(chatId: String!, body: String!, replyTo: Int): MessageResult! createMessage(chatId: String!, body: String!, replyTo: Int): MessageResult!
updateMessage(chatId: String!, id: Int!, body: String!): MessageResult! updateMessage(chatId: String!, id: Int!, body: String!): MessageResult!
deleteMessage(chatId: String!, id: Int!): Result! deleteMessage(chatId: String!, id: Int!): Result!
# auth # auth
confirmEmail(token: String!): AuthResult! confirmEmail(token: String!): AuthResult!
registerUser(email: String!, password: String): AuthResult! registerUser(email: String!, password: String): AuthResult!
requestPasswordUpdate(email: String!): Result! requestPasswordUpdate(email: String!): Result!
updatePassword(password: String!, token: String!): Result! updatePassword(password: String!, token: String!): Result!
# requestEmailConfirmation: User! # requestEmailConfirmation: User!
# shout # shout
createShout(input: ShoutInput!): ShoutResult! createShout(input: ShoutInput!): ShoutResult!
updateShout(input: ShoutInput!): ShoutResult! updateShout(input: ShoutInput!): ShoutResult!
deleteShout(slug: String!): Result! deleteShout(slug: String!): Result!
rateShout(slug: String!, value: Int!): Result! rateShout(slug: String!, value: Int!): Result!
viewShout(slug: String!): Result! viewShout(slug: String!): Result!
# user profile # user profile
# rateUser(value: Int!): Result! # rateUser(value: Int!): Result!
# updateOnlineStatus: Result! # updateOnlineStatus: Result!
updateProfile(profile: ProfileInput!): Result! updateProfile(profile: ProfileInput!): Result!
# topics # topics
createTopic(input: TopicInput!): TopicResult! createTopic(input: TopicInput!): TopicResult!
updateTopic(input: TopicInput!): TopicResult! updateTopic(input: TopicInput!): TopicResult!
topicSubscribe(slug: String!): Result! topicSubscribe(slug: String!): Result!
topicUnsubscribe(slug: String!): Result! topicUnsubscribe(slug: String!): Result!
createComment(body: String!, shout: String!, replyTo: Int): CommentResult! createComment(body: String!, shout: String!, replyTo: Int): CommentResult!
updateComment(id: Int!, body: String!): CommentResult! updateComment(id: Int!, body: String!): CommentResult!
deleteComment(id: Int!): Result! deleteComment(id: Int!): Result!
rateComment(id: Int!, value: Int!): Result! rateComment(id: Int!, value: Int!): Result!
createCommunity(title: String!, desc: String!): Community! createCommunity(title: String!, desc: String!): Community!
updateCommunity(community: CommunityInput!): Community! updateCommunity(community: CommunityInput!): Community!
deleteCommunity(id: Int!): Result! deleteCommunity(id: Int!): Result!
authorSubscribe(slug: String!): Result! authorSubscribe(slug: String!): Result!
authorUnsubscribe(slug: String!): Result! authorUnsubscribe(slug: String!): Result!
} }
################################### Query ################################### Query
type Query { type Query {
# auth # auth
isEmailFree(email: String!): Result! isEmailFree(email: String!): Result!
signIn(email: String!, password: String): AuthResult! signIn(email: String!, password: String): AuthResult!
signOut: Result! signOut: Result!
# profile # profile
getCurrentUser: UserResult! getCurrentUser: UserResult!
getUsersBySlugs(slugs: [String]!): [User]! getUsersBySlugs(slugs: [String]!): [User]!
# rateUser(shout: Int): Int! # rateUser(shout: Int): Int!
getUserRoles(slug: String!): [Role]! getUserRoles(slug: String!): [Role]!
# messages # messages
enterChat(chatId: String!, size: Int = 50): EnterChatResult! enterChat(chatId: String!, size: Int = 50): EnterChatResult!
getMessages(chatId: String!, size: Int!, page: Int!): [Message]! getMessages(chatId: String!, size: Int!, page: Int!): [Message]!
# shouts # shouts
getShoutBySlug(slug: String!): Shout! getShoutBySlug(slug: String!): Shout!
shoutsByTopic(topic: String!, page: Int!, size: Int!): [Shout]! shoutsByTopic(topic: String!, page: Int!, size: Int!): [Shout]!
shoutsByAuthor(author: String!, page: Int!, size: Int!): [Shout]! shoutsByAuthor(author: String!, page: Int!, size: Int!): [Shout]!
shoutsByCommunity(community: String!, page: Int!, size: Int!): [Shout]! shoutsByCommunity(community: String!, page: Int!, size: Int!): [Shout]!
getShoutComments(slug: String!): [Comment]! getShoutComments(slug: String!): [Comment]!
# mainpage # mainpage
topViewed(page: Int!, size: Int!): [Shout]! topViewed(page: Int!, size: Int!): [Shout]!
topMonth(page: Int!, size: Int!): [Shout]! topMonth(page: Int!, size: Int!): [Shout]!
topOverall(page: Int!, size: Int!): [Shout]! topOverall(page: Int!, size: Int!): [Shout]!
recents(page: Int!, size: Int!): [Shout]! recents(page: Int!, size: Int!): [Shout]!
# topics # topics
topicsBySlugs(slugs: [String]): [Topic]! topicsBySlugs(slugs: [String]): [Topic]!
topicsByCommunity(community: String!): [Topic]! topicsByCommunity(community: String!): [Topic]!
topicsByAuthor(author: String!): [Topic]! topicsByAuthor(author: String!): [Topic]!
# getOnlineUsers: [User!]! # getOnlineUsers: [User!]!
# communities # communities
getCommunity(slug: String): Community! getCommunity(slug: String): Community!
getCommunities: [Community]! getCommunities: [Community]!
shoutsSubscribed(page: Int!, size: Int!): [Shout]! shoutsSubscribed(page: Int!, size: Int!): [Shout]!
shoutsReviewed(page: Int!, size: Int!): [Shout]! shoutsReviewed(page: Int!, size: Int!): [Shout]!
shoutsCandidates(size: Int = 10): [Shout]! shoutsCommented(page: Int!, size: Int!): [Shout]!
shoutsCandidates(size: Int = 10): [Shout]!
} }
############################################ Subscription ############################################ Subscription
type Subscription { type Subscription {
chatUpdated(chatId: String!): ChatUpdatedResult! chatUpdated(chatId: String!): ChatUpdatedResult!
onlineUpdated: [User!]! onlineUpdated: [User!]!
shoutUpdated: Shout! shoutUpdated: Shout!
userUpdated: User! userUpdated: User!
topicUpdated(user_slug: String!): Shout! topicUpdated(user_slug: String!): Shout!
commentUpdated(shout: String!): CommentUpdatedResult! commentUpdated(shout: String!): CommentUpdatedResult!
} }
############################################ Entities ############################################ Entities
type Resource { type Resource {
id: Int! id: Int!
name: String! name: String!
} }
type Operation { type Operation {
id: Int! id: Int!
name: String! name: String!
} }
type Permission { type Permission {
operation_id: Int! operation_id: Int!
resource_id: Int! resource_id: Int!
} }
type Role { type Role {
id: Int! id: Int!
name: String! name: String!
community: Int! community: Int!
desc: String desc: String
permissions: [Permission!]! permissions: [Permission!]!
} }
type Rating { type Rating {
rater: String! rater: String!
value: Int! value: Int!
} }
type Notification { type Notification {
kind: String! # unique primary key kind: String! # unique primary key
template: String! template: String!
variables: [String] variables: [String]
} }
type UserNotification { type UserNotification {
id: Int! # primary key id: Int! # primary key
user: Int! user: Int!
kind: String! # NotificationTemplate.name kind: String! # NotificationTemplate.name
values: [String] values: [String]
} }
type User { type User {
id: Int! id: Int!
username: String! # to login, ex. email username: String! # to login, ex. email
createdAt: DateTime! createdAt: DateTime!
slug: String! slug: String!
name: String # to display name: String # to display
email: String email: String
password: String password: String
oauth: String # provider:token oauth: String # provider:token
userpic: String userpic: String
links: [String] links: [String]
emailConfirmed: Boolean # should contain all emails too emailConfirmed: Boolean # should contain all emails too
muted: Boolean muted: Boolean
updatedAt: DateTime updatedAt: DateTime
wasOnlineAt: DateTime wasOnlineAt: DateTime
ratings: [Rating] ratings: [Rating]
bio: String bio: String
notifications: [Int] notifications: [Int]
communities: [Int] # user participating communities communities: [Int] # user participating communities
old_id: String old_id: String
} }
type Message { type Message {
author: String! author: String!
chatRoom: Int! chatRoom: Int!
body: String! body: String!
createdAt: DateTime! createdAt: DateTime!
id: Int! id: Int!
replyTo: Int replyTo: Int
updatedAt: DateTime! updatedAt: DateTime!
visibleForUsers: [Int]! visibleForUsers: [Int]!
} }
type Chat { type Chat {
id: Int! id: Int!
createdAt: DateTime! createdAt: DateTime!
updatedAt: DateTime! updatedAt: DateTime!
description: String description: String
} }
type Comment { type Comment {
id: Int! id: Int!
author: User! author: User!
body: String! body: String!
replyTo: Int replyTo: Int
createdAt: DateTime! createdAt: DateTime!
updatedAt: DateTime updatedAt: DateTime
updatedBy: Int updatedBy: Int
shout: Int! shout: Int!
deletedAt: DateTime deletedAt: DateTime
deletedBy: Int deletedBy: Int
ratings: [CommentRating] ratings: [CommentRating]
views: Int views: Int
old_id: String old_id: String
old_thread: String old_thread: String
} }
type CommentRating { type CommentRating {
id: Int! id: Int!
comment_id: Int! comment_id: Int!
createdBy: String! createdBy: String!
createdAt: DateTime! createdAt: DateTime!
value: Int! value: Int!
} }
# is publication # is publication
type Shout { type Shout {
slug: String! slug: String!
body: String! body: String!
createdAt: DateTime! createdAt: DateTime!
authors: [User!]! authors: [User!]!
ratings: [Rating] ratings: [Rating]
visibleFor: [User] visibleFor: [User]
community: Int community: Int
cover: String cover: String
layout: String layout: String
# replyTo: Shout # replyTo: Shout
versionOf: Shout versionOf: Shout
tags: [String] # actual values tags: [String] # actual values
topics: [Topic] topics: [Topic]
mainTopic: String mainTopic: String
title: String title: String
subtitle: String subtitle: String
updatedAt: DateTime updatedAt: DateTime
updatedBy: Int # can be user id? updatedBy: Int # can be user id?
deletedAt: DateTime deletedAt: DateTime
deletedBy: Int deletedBy: Int
publishedBy: Int # if there is no published field - it is not published publishedBy: Int # if there is no published field - it is not published
publishedAt: DateTime publishedAt: DateTime
stat: ShoutStat stat: ShoutStat
} }
type ShoutStat { type ShoutStat {
views: Int! views: Int!
comments: Int! comments: Int!
ratings: Int! ratings: Int!
} }
type Community { type Community {
slug: String! slug: String!
name: String! name: String!
desc: String desc: String
pic: String! pic: String!
} }
type TopicStat { type TopicStat {
shouts: Int! shouts: Int!
views: Int! views: Int!
subscriptions: Int! subscriptions: Int!
authors: Int! authors: Int!
} }
type Topic { type Topic {
slug: String! # ID slug: String! # ID
title: String title: String
body: String body: String
pic: String pic: String
parents: [String] # NOTE: topic can have parent topics parents: [String] # NOTE: topic can have parent topics
children: [String] # and children children: [String] # and children
community: String! community: String!
topicStat: TopicStat topicStat: TopicStat
} }
# TODO: resolvers to add/remove topics from publication # TODO: resolvers to add/remove topics from publication
type Proposal { type Proposal {
body: String! body: String!
shout: Int! shout: Int!
range: String # full / 0:2340 range: String # full / 0:2340
author: Int! author: Int!
createdAt: DateTime! createdAt: DateTime!
} }
type Token { type Token {
createdAt: DateTime! createdAt: DateTime!
expiresAt: DateTime expiresAt: DateTime
id: Int! id: Int!
ownerId: Int! ownerId: Int!
usedAt: DateTime usedAt: DateTime
value: String! value: String!
} }