Only update the events and event_json tables for rejected events

This commit is contained in:
Mark Haines 2016-07-25 18:44:30 +01:00
parent 8f7f4cb92b
commit 1b3c3e6d68
2 changed files with 63 additions and 52 deletions

View file

@ -407,21 +407,11 @@ class EventsStore(SQLBaseStore):
event.room_id, event.internal_metadata.stream_ordering, event.room_id, event.internal_metadata.stream_ordering,
) )
if not event.internal_metadata.is_outlier(): if not event.internal_metadata.is_outlier() and not context.rejected:
depth_updates[event.room_id] = max( depth_updates[event.room_id] = max(
event.depth, depth_updates.get(event.room_id, event.depth) event.depth, depth_updates.get(event.room_id, event.depth)
) )
if context.push_actions:
self._set_push_actions_for_event_and_users_txn(
txn, event, context.push_actions
)
if event.type == EventTypes.Redaction and event.redacts is not None:
self._remove_push_actions_for_event_id_txn(
txn, event.room_id, event.redacts
)
for room_id, depth in depth_updates.items(): for room_id, depth in depth_updates.items():
self._update_min_depth_for_room_txn(txn, room_id, depth) self._update_min_depth_for_room_txn(txn, room_id, depth)
@ -431,6 +421,7 @@ class EventsStore(SQLBaseStore):
), ),
[event.event_id for event, _ in events_and_contexts] [event.event_id for event, _ in events_and_contexts]
) )
have_persisted = { have_persisted = {
event_id: outlier event_id: outlier
for event_id, outlier in txn.fetchall() for event_id, outlier in txn.fetchall()
@ -442,6 +433,9 @@ class EventsStore(SQLBaseStore):
# Handle the case of the list including the same event multiple # Handle the case of the list including the same event multiple
# times. The tricky thing here is when they differ by whether # times. The tricky thing here is when they differ by whether
# they are an outlier. # they are an outlier.
if context.rejected:
continue
if event.event_id in event_map: if event.event_id in event_map:
other = event_map[event.event_id] other = event_map[event.event_id]
@ -498,7 +492,7 @@ class EventsStore(SQLBaseStore):
sql, sql,
(False, event.event_id,) (False, event.event_id,)
) )
if not context.rejected:
self._update_extremeties(txn, [event]) self._update_extremeties(txn, [event])
events_and_contexts = [ events_and_contexts = [
@ -508,39 +502,8 @@ class EventsStore(SQLBaseStore):
if not events_and_contexts: if not events_and_contexts:
return return
self._store_mult_state_groups_txn(txn, events_and_contexts) # From this point onwards the events are only events that we haven't
# seen before.
self._handle_mult_prev_events(
txn,
events=[
event for event, context in events_and_contexts
if not context.rejected
],
)
for event, _ in events_and_contexts:
if event.type == EventTypes.Name:
self._store_room_name_txn(txn, event)
elif event.type == EventTypes.Topic:
self._store_room_topic_txn(txn, event)
elif event.type == EventTypes.Message:
self._store_room_message_txn(txn, event)
elif event.type == EventTypes.Redaction:
self._store_redaction(txn, event)
elif event.type == EventTypes.RoomHistoryVisibility:
self._store_history_visibility_txn(txn, event)
elif event.type == EventTypes.GuestAccess:
self._store_guest_access_txn(txn, event)
self._store_room_members_txn(
txn,
[
event
for event, _ in events_and_contexts
if event.type == EventTypes.Member
],
backfilled=backfilled,
)
def event_dict(event): def event_dict(event):
return { return {
@ -594,11 +557,28 @@ class EventsStore(SQLBaseStore):
], ],
) )
to_remove = set()
for event, context in events_and_contexts: for event, context in events_and_contexts:
if context.rejected: if context.rejected:
self._store_rejections_txn( self._store_rejections_txn(
txn, event.event_id, context.rejected txn, event.event_id, context.rejected
) )
to_remove.add(event.event_id)
events_and_contexts = [
ec for ec in events_and_contexts if ec[0].event_id not in to_remove
]
if not events_and_contexts:
return
# From this point onwards the events are only ones that weren't rejected.
for event, context in events_and_contexts:
if context.push_actions:
self._set_push_actions_for_event_and_users_txn(
txn, event, context.push_actions
)
self._simple_insert_many_txn( self._simple_insert_many_txn(
txn, txn,
@ -614,6 +594,42 @@ class EventsStore(SQLBaseStore):
], ],
) )
if event.type == EventTypes.Redaction and event.redacts is not None:
self._remove_push_actions_for_event_id_txn(
txn, event.room_id, event.redacts
)
self._store_mult_state_groups_txn(txn, events_and_contexts)
self._handle_mult_prev_events(
txn,
events=[event for event, _ in events_and_contexts],
)
for event, _ in events_and_contexts:
if event.type == EventTypes.Name:
self._store_room_name_txn(txn, event)
elif event.type == EventTypes.Topic:
self._store_room_topic_txn(txn, event)
elif event.type == EventTypes.Message:
self._store_room_message_txn(txn, event)
elif event.type == EventTypes.Redaction:
self._store_redaction(txn, event)
elif event.type == EventTypes.RoomHistoryVisibility:
self._store_history_visibility_txn(txn, event)
elif event.type == EventTypes.GuestAccess:
self._store_guest_access_txn(txn, event)
self._store_room_members_txn(
txn,
[
event
for event, _ in events_and_contexts
if event.type == EventTypes.Member
],
backfilled=backfilled,
)
self._store_event_reference_hashes_txn( self._store_event_reference_hashes_txn(
txn, [event for event, _ in events_and_contexts] txn, [event for event, _ in events_and_contexts]
) )
@ -670,11 +686,6 @@ class EventsStore(SQLBaseStore):
# Outlier events shouldn't clobber the current state. # Outlier events shouldn't clobber the current state.
continue continue
if context.rejected:
# If the event failed it's auth checks then it shouldn't
# clobbler the current state.
continue
txn.call_after( txn.call_after(
self._get_current_state_for_key.invalidate, self._get_current_state_for_key.invalidate,
(event.room_id, event.type, event.state_key,) (event.room_id, event.type, event.state_key,)

View file

@ -79,7 +79,7 @@ class StateStore(SQLBaseStore):
state_events = dict(context.current_state) state_events = dict(context.current_state)
if event.is_state() and not context.rejected: if event.is_state():
state_events[(event.type, event.state_key)] = event state_events[(event.type, event.state_key)] = event
state_group = context.new_state_group_id state_group = context.new_state_group_id