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