scalar-fix
All checks were successful
Deploy on push / deploy (push) Successful in 23s

This commit is contained in:
Untone 2024-03-28 14:05:46 +03:00
parent 6f016f236d
commit e2faec5893
3 changed files with 67 additions and 63 deletions

View File

@ -122,9 +122,9 @@ def get_notifications_grouped(
if (groups_amount + offset) >= limit:
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_id = shout.get('id')
author_id = shout.get('created_by')
@ -139,16 +139,19 @@ def get_notifications_grouped(
thread_id,
shout=shout,
authors=[author],
action=notification.action,
entity=notification.entity,
action=notification.action.scalar(),
entity=notification.entity.scalar(),
)
groups_by_thread[thread_id] = group
groups_amount += 1
elif notification.entity == NotificationEntity.REACTION.value:
elif notification.entity.scalar() == NotificationEntity.REACTION.value:
reaction = payload
if not isinstance(shout, dict):
raise ValueError('reaction data is not consistent')
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:
author = session.query(Author).filter(Author.id == author_id).first()
shout = session.query(Shout).filter(Shout.id == shout_id).first()
@ -172,21 +175,21 @@ def get_notifications_grouped(
authors=[author],
shout=shout,
reactions=[reaction],
entity=notification.entity,
action=notification.action,
entity=notification.entity.scalar(),
action=notification.action.scalar(),
)
if group:
groups_by_thread[thread_id] = group
groups_amount += 1
elif notification.entity == 'follower':
elif notification.entity.scalar() == 'follower':
thread_id = 'followers'
follower = json.loads(payload)
group = groups_by_thread.get(thread_id)
if group:
if notification.action == 'follow':
if notification.action.scalar() == 'follow':
group['authors'].append(follower)
elif notification.action == 'unfollow':
elif notification.action.scalar() == 'unfollow':
follower_id = follower.get('id')
for author in group['authors']:
if author.get('id') == follower_id:
@ -196,8 +199,8 @@ def get_notifications_grouped(
group = group_notification(
thread_id,
authors=[follower],
entity=notification.entity,
action=notification.action,
entity=notification.entity.scalar(),
action=notification.action.scalar(),
)
groups_amount += 1
groups_by_thread[thread_id] = group
@ -302,11 +305,11 @@ async def notifications_seen_thread(_, info, thread: str, after: int):
)
exclude = set()
for nr in removed_reaction_notifications:
reaction = json.loads(nr.payload)
reaction = json.loads(nr.payload.scalar())
reaction_id = reaction.get('id')
exclude.add(reaction_id)
for n in new_reaction_notifications:
reaction = json.loads(n.payload)
reaction = json.loads(n.payload.scalar())
reaction_id = reaction.get('id')
if (
reaction_id not in exclude

View File

@ -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 = 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:
with local_session() as session:
author = session.query(Author).filter(Author.user == user_id).first()

View File

@ -120,6 +120,7 @@ class SearchService:
await self.recreate_index()
async def recreate_index(self):
if self.client:
async with self.lock:
self.client.indices.delete(index=self.index_name, ignore_unavailable=True)
await self.check_index()