This commit is contained in:
parent
6f016f236d
commit
e2faec5893
|
@ -122,9 +122,9 @@ def get_notifications_grouped(
|
||||||
if (groups_amount + offset) >= limit:
|
if (groups_amount + offset) >= limit:
|
||||||
break
|
break
|
||||||
|
|
||||||
payload = json.loads(notification.payload)
|
payload = json.loads(notification.payload.scalar())
|
||||||
|
|
||||||
if notification.entity == NotificationEntity.SHOUT.value:
|
if notification.entity.scalar() == NotificationEntity.SHOUT.value:
|
||||||
shout = payload
|
shout = payload
|
||||||
shout_id = shout.get('id')
|
shout_id = shout.get('id')
|
||||||
author_id = shout.get('created_by')
|
author_id = shout.get('created_by')
|
||||||
|
@ -139,16 +139,19 @@ def get_notifications_grouped(
|
||||||
thread_id,
|
thread_id,
|
||||||
shout=shout,
|
shout=shout,
|
||||||
authors=[author],
|
authors=[author],
|
||||||
action=notification.action,
|
action=notification.action.scalar(),
|
||||||
entity=notification.entity,
|
entity=notification.entity.scalar(),
|
||||||
)
|
)
|
||||||
groups_by_thread[thread_id] = group
|
groups_by_thread[thread_id] = group
|
||||||
groups_amount += 1
|
groups_amount += 1
|
||||||
|
|
||||||
elif notification.entity == NotificationEntity.REACTION.value:
|
elif notification.entity.scalar() == NotificationEntity.REACTION.value:
|
||||||
reaction = payload
|
reaction = payload
|
||||||
|
if not isinstance(shout, dict):
|
||||||
|
raise ValueError('reaction data is not consistent')
|
||||||
shout_id = shout.get('shout')
|
shout_id = shout.get('shout')
|
||||||
author_id = shout.get('created_by')
|
author_id = shout.get('created_by', 0)
|
||||||
|
if shout_id and author_id:
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
author = session.query(Author).filter(Author.id == author_id).first()
|
author = session.query(Author).filter(Author.id == author_id).first()
|
||||||
shout = session.query(Shout).filter(Shout.id == shout_id).first()
|
shout = session.query(Shout).filter(Shout.id == shout_id).first()
|
||||||
|
@ -172,21 +175,21 @@ def get_notifications_grouped(
|
||||||
authors=[author],
|
authors=[author],
|
||||||
shout=shout,
|
shout=shout,
|
||||||
reactions=[reaction],
|
reactions=[reaction],
|
||||||
entity=notification.entity,
|
entity=notification.entity.scalar(),
|
||||||
action=notification.action,
|
action=notification.action.scalar(),
|
||||||
)
|
)
|
||||||
if group:
|
if group:
|
||||||
groups_by_thread[thread_id] = group
|
groups_by_thread[thread_id] = group
|
||||||
groups_amount += 1
|
groups_amount += 1
|
||||||
|
|
||||||
elif notification.entity == 'follower':
|
elif notification.entity.scalar() == 'follower':
|
||||||
thread_id = 'followers'
|
thread_id = 'followers'
|
||||||
follower = json.loads(payload)
|
follower = json.loads(payload)
|
||||||
group = groups_by_thread.get(thread_id)
|
group = groups_by_thread.get(thread_id)
|
||||||
if group:
|
if group:
|
||||||
if notification.action == 'follow':
|
if notification.action.scalar() == 'follow':
|
||||||
group['authors'].append(follower)
|
group['authors'].append(follower)
|
||||||
elif notification.action == 'unfollow':
|
elif notification.action.scalar() == 'unfollow':
|
||||||
follower_id = follower.get('id')
|
follower_id = follower.get('id')
|
||||||
for author in group['authors']:
|
for author in group['authors']:
|
||||||
if author.get('id') == follower_id:
|
if author.get('id') == follower_id:
|
||||||
|
@ -196,8 +199,8 @@ def get_notifications_grouped(
|
||||||
group = group_notification(
|
group = group_notification(
|
||||||
thread_id,
|
thread_id,
|
||||||
authors=[follower],
|
authors=[follower],
|
||||||
entity=notification.entity,
|
entity=notification.entity.scalar(),
|
||||||
action=notification.action,
|
action=notification.action.scalar(),
|
||||||
)
|
)
|
||||||
groups_amount += 1
|
groups_amount += 1
|
||||||
groups_by_thread[thread_id] = group
|
groups_by_thread[thread_id] = group
|
||||||
|
@ -302,11 +305,11 @@ async def notifications_seen_thread(_, info, thread: str, after: int):
|
||||||
)
|
)
|
||||||
exclude = set()
|
exclude = set()
|
||||||
for nr in removed_reaction_notifications:
|
for nr in removed_reaction_notifications:
|
||||||
reaction = json.loads(nr.payload)
|
reaction = json.loads(nr.payload.scalar())
|
||||||
reaction_id = reaction.get('id')
|
reaction_id = reaction.get('id')
|
||||||
exclude.add(reaction_id)
|
exclude.add(reaction_id)
|
||||||
for n in new_reaction_notifications:
|
for n in new_reaction_notifications:
|
||||||
reaction = json.loads(n.payload)
|
reaction = json.loads(n.payload.scalar())
|
||||||
reaction_id = reaction.get('id')
|
reaction_id = reaction.get('id')
|
||||||
if (
|
if (
|
||||||
reaction_id not in exclude
|
reaction_id not in exclude
|
||||||
|
|
|
@ -338,7 +338,7 @@ async def load_shouts_unrated(_, info, limit: int = 50, offset: int = 0):
|
||||||
q = add_reaction_stat_columns(q, aliased_reaction)
|
q = add_reaction_stat_columns(q, aliased_reaction)
|
||||||
|
|
||||||
q = q.group_by(Shout.id).order_by(func.random()).limit(limit).offset(offset)
|
q = q.group_by(Shout.id).order_by(func.random()).limit(limit).offset(offset)
|
||||||
user_id = info.context.get('user_id') if isinstance(info.context, {}) else None
|
user_id = info.context.get('user_id') if isinstance(info.context, dict) else None
|
||||||
if user_id:
|
if user_id:
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
author = session.query(Author).filter(Author.user == user_id).first()
|
author = session.query(Author).filter(Author.user == user_id).first()
|
||||||
|
|
|
@ -120,6 +120,7 @@ class SearchService:
|
||||||
await self.recreate_index()
|
await self.recreate_index()
|
||||||
|
|
||||||
async def recreate_index(self):
|
async def recreate_index(self):
|
||||||
|
if self.client:
|
||||||
async with self.lock:
|
async with self.lock:
|
||||||
self.client.indices.delete(index=self.index_name, ignore_unavailable=True)
|
self.client.indices.delete(index=self.index_name, ignore_unavailable=True)
|
||||||
await self.check_index()
|
await self.check_index()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user