some fixes, schema update
This commit is contained in:
parent
6c7e56909a
commit
835b51de36
|
@ -199,32 +199,12 @@ async def delete_reaction(_, info, rid):
|
|||
return {}
|
||||
|
||||
|
||||
@query.field("loadReactionsBy")
|
||||
async def load_reactions_by(_, info, by, limit=50, offset=0):
|
||||
"""
|
||||
:param by: {
|
||||
shout: 'some-slug'
|
||||
author: 'discours',
|
||||
topic: 'culture',
|
||||
body: 'something else',
|
||||
stat: 'rating' | 'comments' | 'reacted' | 'views',
|
||||
days: 30
|
||||
}
|
||||
:param limit: int amount of shouts
|
||||
:param offset: int offset in this order
|
||||
:return: Reaction[]
|
||||
"""
|
||||
|
||||
q = select(Reaction).join(
|
||||
Shout
|
||||
).where(
|
||||
Reaction.deletedAt.is_(None)
|
||||
)
|
||||
if by.get("slug"):
|
||||
def prepare_reactions(q, by, user=None):
|
||||
if by.get("shout"):
|
||||
q = q.filter(Shout.slug == by["slug"])
|
||||
else:
|
||||
if by.get("reacted"):
|
||||
user = info.context["request"].user
|
||||
if user:
|
||||
q = q.filter(Reaction.createdBy == user.slug)
|
||||
if by.get("author"):
|
||||
q = q.filter(Reaction.createdBy == by["author"])
|
||||
|
@ -240,8 +220,40 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
|
|||
q = q.filter(Reaction.createdAt > before)
|
||||
|
||||
q = q.group_by(Reaction.id).order_by(
|
||||
desc(by.get("order") or Reaction.createdAt)
|
||||
).limit(limit).offset(offset)
|
||||
desc(by.get("sort") or Reaction.createdAt)
|
||||
)
|
||||
return q
|
||||
|
||||
|
||||
@query.field("loadReactionsBy")
|
||||
async def load_reactions_by(_, info, by, limit=50, offset=0):
|
||||
"""
|
||||
:param by: {
|
||||
shout: 'some-slug'
|
||||
author: 'discours',
|
||||
topic: 'culture',
|
||||
body: 'something else' | true,
|
||||
sort: 'rating' | 'comments' | 'reacted' | 'views',
|
||||
days: 30
|
||||
}
|
||||
:param limit: int amount of shouts
|
||||
:param offset: int offset in this order
|
||||
:return: Reaction[]
|
||||
"""
|
||||
user = None
|
||||
try:
|
||||
user = info.context["request"].user
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
q = select(Reaction).join(
|
||||
Shout,
|
||||
Reaction.shout == Shout.slug
|
||||
).where(
|
||||
Reaction.deletedAt.is_(None)
|
||||
)
|
||||
q = prepare_reactions(q, by, user)
|
||||
q = q.limit(limit).offset(offset)
|
||||
|
||||
rrr = []
|
||||
with local_session() as session:
|
||||
|
|
|
@ -255,7 +255,7 @@ input ReactionBy {
|
|||
author: String
|
||||
order: String
|
||||
days: Int
|
||||
stat: String
|
||||
sort: String
|
||||
}
|
||||
################################### Query
|
||||
|
||||
|
|
|
@ -99,18 +99,20 @@ class ViewedStorage:
|
|||
period = 24 * 60 * 60 # one time a day
|
||||
client = None
|
||||
auth_result = None
|
||||
disabled = False
|
||||
|
||||
@staticmethod
|
||||
async def init():
|
||||
if token:
|
||||
self = ViewedStorage
|
||||
async with self.lock:
|
||||
if token:
|
||||
self.client = create_client({
|
||||
"Authorization": "Bearer %s" % str(token)
|
||||
}, schema=schema_str)
|
||||
print("[stat.viewed] authorized permanentely by ackee.discours.io: %s" % token)
|
||||
else:
|
||||
print("[stat.viewed] please, set ACKEE_TOKEN")
|
||||
print("[stat.viewed] please set ACKEE_TOKEN")
|
||||
self.disabled = True
|
||||
|
||||
@staticmethod
|
||||
async def update(session):
|
||||
|
@ -203,8 +205,11 @@ class ViewedStorage:
|
|||
|
||||
@staticmethod
|
||||
async def worker():
|
||||
self = ViewedStorage
|
||||
failed = 0
|
||||
self = ViewedStorage
|
||||
if self.disabled:
|
||||
return
|
||||
async with self.lock:
|
||||
while True:
|
||||
try:
|
||||
with local_session() as session:
|
||||
|
|
Loading…
Reference in New Issue
Block a user