Refactor _set_push_actions_for_event_and_users_txn to use events_and_contexts
This commit is contained in:
parent
324c3e9399
commit
ad0ccf15ea
|
@ -88,11 +88,13 @@ class EventPushActionsStore(SQLBaseStore):
|
||||||
self._rotate_notifs, 30 * 60 * 1000
|
self._rotate_notifs, 30 * 60 * 1000
|
||||||
)
|
)
|
||||||
|
|
||||||
def _set_push_actions_for_event_and_users_txn(self, txn, event):
|
def _set_push_actions_for_event_and_users_txn(self, txn, events_and_contexts):
|
||||||
"""
|
"""Handles moving push actions from staging table to main
|
||||||
|
event_push_actions table for all events in `events_and_contexts`.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
event: the event set actions for
|
events_and_contexts (list[(EventBase, EventContext)]): events
|
||||||
tuples: list of tuples of (user_id, actions)
|
we are persisting
|
||||||
"""
|
"""
|
||||||
|
|
||||||
sql = """
|
sql = """
|
||||||
|
@ -105,11 +107,16 @@ class EventPushActionsStore(SQLBaseStore):
|
||||||
WHERE event_id = ?
|
WHERE event_id = ?
|
||||||
"""
|
"""
|
||||||
|
|
||||||
txn.execute(sql, (
|
if events_and_contexts:
|
||||||
|
txn.executemany(sql, (
|
||||||
|
(
|
||||||
event.room_id, event.internal_metadata.stream_ordering,
|
event.room_id, event.internal_metadata.stream_ordering,
|
||||||
event.depth, event.event_id,
|
event.depth, event.event_id,
|
||||||
|
)
|
||||||
|
for event, _ in events_and_contexts
|
||||||
))
|
))
|
||||||
|
|
||||||
|
for event, _ in events_and_contexts:
|
||||||
user_ids = self._simple_select_onecol_txn(
|
user_ids = self._simple_select_onecol_txn(
|
||||||
txn,
|
txn,
|
||||||
table="event_push_actions_staging",
|
table="event_push_actions_staging",
|
||||||
|
@ -119,20 +126,20 @@ class EventPushActionsStore(SQLBaseStore):
|
||||||
retcol="user_id",
|
retcol="user_id",
|
||||||
)
|
)
|
||||||
|
|
||||||
self._simple_delete_txn(
|
|
||||||
txn,
|
|
||||||
table="event_push_actions_staging",
|
|
||||||
keyvalues={
|
|
||||||
"event_id": event.event_id,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
for uid in user_ids:
|
for uid in user_ids:
|
||||||
txn.call_after(
|
txn.call_after(
|
||||||
self.get_unread_event_push_actions_by_room_for_user.invalidate_many,
|
self.get_unread_event_push_actions_by_room_for_user.invalidate_many,
|
||||||
(event.room_id, uid,)
|
(event.room_id, uid,)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
txn.executemany(
|
||||||
|
"DELETE FROM event_push_actions_staging WHERE event_id = ?",
|
||||||
|
(
|
||||||
|
(event.event_id,)
|
||||||
|
for event, _ in events_and_contexts
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@cachedInlineCallbacks(num_args=3, tree=True, max_entries=5000)
|
@cachedInlineCallbacks(num_args=3, tree=True, max_entries=5000)
|
||||||
def get_unread_event_push_actions_by_room_for_user(
|
def get_unread_event_push_actions_by_room_for_user(
|
||||||
self, room_id, user_id, last_read_event_id
|
self, room_id, user_id, last_read_event_id
|
||||||
|
|
|
@ -1162,16 +1162,17 @@ class EventsStore(SQLBaseStore):
|
||||||
backfilled (bool): True if the events were backfilled
|
backfilled (bool): True if the events were backfilled
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Insert all the push actions into the event_push_actions table.
|
||||||
|
self._set_push_actions_for_event_and_users_txn(
|
||||||
|
txn,
|
||||||
|
events_and_contexts=events_and_contexts,
|
||||||
|
)
|
||||||
|
|
||||||
if not events_and_contexts:
|
if not events_and_contexts:
|
||||||
# nothing to do here
|
# nothing to do here
|
||||||
return
|
return
|
||||||
|
|
||||||
for event, context in events_and_contexts:
|
for event, context in events_and_contexts:
|
||||||
# Insert all the push actions into the event_push_actions table.
|
|
||||||
self._set_push_actions_for_event_and_users_txn(
|
|
||||||
txn, event,
|
|
||||||
)
|
|
||||||
|
|
||||||
if event.type == EventTypes.Redaction and event.redacts is not None:
|
if event.type == EventTypes.Redaction and event.redacts is not None:
|
||||||
# Remove the entries in the event_push_actions table for the
|
# Remove the entries in the event_push_actions table for the
|
||||||
# redacted event.
|
# redacted event.
|
||||||
|
|
Loading…
Reference in New Issue