mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 11:33:51 +01:00
Insert push actions in a single db query rather than one per user/profile_tag
This commit is contained in:
parent
77f06856b6
commit
4c8f6a7e42
2 changed files with 24 additions and 17 deletions
|
@ -43,7 +43,9 @@ class ActionGenerator:
|
||||||
|
|
||||||
actions_by_user = bulk_evaluator.action_for_event_by_user(event)
|
actions_by_user = bulk_evaluator.action_for_event_by_user(event)
|
||||||
|
|
||||||
for uid,actions in actions_by_user.items():
|
yield self.store.set_actions_for_event_and_users(
|
||||||
self.store.set_actions_for_event(
|
event,
|
||||||
event, uid, None, actions
|
[
|
||||||
|
(uid, None, actions) for uid, actions in actions_by_user.items()
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,22 +24,27 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class EventActionsStore(SQLBaseStore):
|
class EventActionsStore(SQLBaseStore):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def set_actions_for_event(self, event, user_id, profile_tag, actions):
|
def set_actions_for_event_and_users(self, event, tuples):
|
||||||
actionsJson = json.dumps(actions)
|
"""
|
||||||
|
:param event: the event set actions for
|
||||||
ret = yield self.runInteraction(
|
:param tuples: list of tuples of (user_id, profile_tag, actions)
|
||||||
"_set_actions_for_event",
|
"""
|
||||||
self._simple_upsert_txn,
|
values = []
|
||||||
EventActionsTable.table_name,
|
for uid, profile_tag, actions in tuples:
|
||||||
{
|
values.append({
|
||||||
'room_id': event['room_id'],
|
'room_id': event['room_id'],
|
||||||
'event_id': event['event_id'],
|
'event_id': event['event_id'],
|
||||||
'user_id': user_id,
|
'user_id': uid,
|
||||||
'profile_tag': profile_tag
|
'profile_tag': profile_tag,
|
||||||
},
|
'actions': json.dumps(actions)
|
||||||
{'actions': actionsJson}
|
})
|
||||||
|
|
||||||
|
yield self.runInteraction(
|
||||||
|
"set_actions_for_event_and_users",
|
||||||
|
self._simple_insert_many_txn,
|
||||||
|
EventActionsTable.table_name,
|
||||||
|
values
|
||||||
)
|
)
|
||||||
defer.returnValue(ret)
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def get_unread_event_actions_by_room_for_user(
|
def get_unread_event_actions_by_room_for_user(
|
||||||
|
|
Loading…
Reference in a new issue