0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 18:03:53 +01:00

replace get_prev_events_and_hashes_for_room with get_prev_events_for_room in create_new_client_event

This commit is contained in:
Richard van der Hoff 2020-01-03 16:09:24 +00:00
parent 5a04781643
commit 15720092ac
2 changed files with 38 additions and 9 deletions

View file

@ -739,17 +739,11 @@ class EventCreationHandler(object):
"Attempting to create an event with %i prev_events" "Attempting to create an event with %i prev_events"
% (len(prev_events_and_hashes),) % (len(prev_events_and_hashes),)
) )
prev_event_ids = [event_id for event_id, _, _ in prev_events_and_hashes]
else: else:
prev_events_and_hashes = yield self.store.get_prev_events_and_hashes_for_room( prev_event_ids = yield self.store.get_prev_events_for_room(builder.room_id)
builder.room_id
)
prev_events = [ event = yield builder.build(prev_event_ids=prev_event_ids)
(event_id, prev_hashes)
for event_id, prev_hashes, _ in prev_events_and_hashes
]
event = yield builder.build(prev_event_ids=[p for p, _ in prev_events])
context = yield self.state.compute_event_context(event) context = yield self.state.compute_event_context(event)
if requester: if requester:
context.app_service = requester.app_service context.app_service = requester.app_service

View file

@ -177,6 +177,41 @@ class EventFederationWorkerStore(EventsWorkerStore, SignatureWorkerStore, SQLBas
return res return res
def get_prev_events_for_room(self, room_id: str):
"""
Gets a subset of the current forward extremities in the given room.
Limits the result to 10 extremities, so that we can avoid creating
events which refer to hundreds of prev_events.
Args:
room_id (str): room_id
Returns:
Deferred[List[str]]: the event ids of the forward extremites
"""
return self.db.runInteraction(
"get_prev_events_for_room", self._get_prev_events_for_room_txn, room_id
)
def _get_prev_events_for_room_txn(self, txn, room_id: str):
# we just use the 10 newest events. Older events will become
# prev_events of future events.
sql = """
SELECT e.event_id FROM event_forward_extremities AS f
INNER JOIN events AS e USING (event_id)
WHERE f.room_id = ?
ORDER BY e.depth DESC
LIMIT 10
"""
txn.execute(sql, (room_id,))
return [row[0] for row in txn]
def get_latest_event_ids_and_hashes_in_room(self, room_id): def get_latest_event_ids_and_hashes_in_room(self, room_id):
""" """
Gets the current forward extremities in the given room Gets the current forward extremities in the given room