storage and collection fixes
This commit is contained in:
parent
f0b625af53
commit
bdc864f443
|
@ -57,22 +57,22 @@ async def delete_collection(_, info, slug):
|
|||
|
||||
return {}
|
||||
|
||||
@query.field("getCollection")
|
||||
async def get_collection(_, info, userslug, colslug):
|
||||
@query.field("getUserCollections")
|
||||
async def get_user_collections(_, info, userslug):
|
||||
collections = []
|
||||
with local_session() as session:
|
||||
user = session.query(User).filter(User.slug == userslug).first()
|
||||
if user:
|
||||
collection = session.\
|
||||
# TODO: check rights here
|
||||
collections = session.\
|
||||
query(Collection).\
|
||||
where(and_(Collection.createdBy == user.id, Collection.slug == colslug)).\
|
||||
first()
|
||||
if not collection:
|
||||
return {"error": "collection not found"}
|
||||
return collection
|
||||
where(and_(Collection.createdBy == userslug, Collection.publishedAt != None)).\
|
||||
all()
|
||||
return collections
|
||||
|
||||
@query.field("getMyColelctions")
|
||||
@login_required
|
||||
async def get_collections(_, info):
|
||||
async def get_my_collections(_, info):
|
||||
auth = info.context["request"].auth
|
||||
user_id = auth.user_id
|
||||
with local_session() as session:
|
||||
|
|
|
@ -252,9 +252,9 @@ type Query {
|
|||
topicsByCommunity(community: String!): [Topic]!
|
||||
topicsByAuthor(author: String!): [Topic]!
|
||||
|
||||
# collection
|
||||
getCollection(author: String!, slug: String!): Collection!
|
||||
shoutsByCollection(collection: String, page: Int, size: Int): [Shout]!
|
||||
# collections
|
||||
getUserCollections(author: String!): [Collection]!
|
||||
shoutsByCollection(collection: String!, page: Int, size: Int): [Shout]!
|
||||
|
||||
# communities
|
||||
getCommunity(slug: String): Community!
|
||||
|
@ -429,6 +429,7 @@ type Collection {
|
|||
title: String!
|
||||
desc: String
|
||||
pic: String!
|
||||
publishedAt: DateTime
|
||||
createdAt: DateTime!
|
||||
createdBy: User!
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class ReactedStorage:
|
|||
lock = asyncio.Lock()
|
||||
|
||||
@staticmethod
|
||||
def prepare(session):
|
||||
def init(session):
|
||||
self = ReactedStorage
|
||||
all_reactions = session.query(ReactedByDay).all()
|
||||
day_start = datetime.now().replace(hour=0, minute=0, second=0)
|
||||
|
@ -101,25 +101,10 @@ class ReactedStorage:
|
|||
self = ReactedStorage
|
||||
reaction: ReactedByDay = None
|
||||
async with self.lock:
|
||||
reaction = ReactedByDay.create(shout=shout_slug, kind=kind, reply=reply_id)
|
||||
self.reacted['shouts'][shout_slug] = self.reacted['shouts'].get(shout_slug, [])
|
||||
self.reacted['shouts'][shout_slug].append(reaction)
|
||||
if reply_id:
|
||||
self.reacted['reaction'][reply_id] = self.reacted['reactions'].get(shout_slug, [])
|
||||
self.reacted['reaction'][reply_id].append(reaction)
|
||||
|
||||
@staticmethod
|
||||
async def worker():
|
||||
while True:
|
||||
try:
|
||||
with local_session() as session:
|
||||
ReactedStorage.prepare(session)
|
||||
print("[stat.reacted] updated")
|
||||
except Exception as err:
|
||||
print("[stat.reacted] error: %s" % (err))
|
||||
raise err
|
||||
await asyncio.sleep(ReactedStorage.period)
|
||||
|
||||
@staticmethod
|
||||
def init(session):
|
||||
ReactedStorage.prepare(session)
|
||||
with local_session() as session:
|
||||
reaction = ReactedByDay.create(shout=shout_slug, kind=kind, reply=reply_id)
|
||||
self.reacted['shouts'][shout_slug] = self.reacted['shouts'].get(shout_slug, [])
|
||||
self.reacted['shouts'][shout_slug].append(reaction)
|
||||
if reply_id:
|
||||
self.reacted['reaction'][reply_id] = self.reacted['reactions'].get(shout_slug, [])
|
||||
self.reacted['reaction'][reply_id].append(reaction)
|
Loading…
Reference in New Issue
Block a user