mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Fix _get_backfill_events to return events in the correct order
This commit is contained in:
parent
20814fabdd
commit
2bc60c55af
@ -17,6 +17,7 @@ from ._base import SQLBaseStore, cached
|
|||||||
from syutil.base64util import encode_base64
|
from syutil.base64util import encode_base64
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from Queue import PriorityQueue
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -380,41 +381,41 @@ class EventFederationStore(SQLBaseStore):
|
|||||||
|
|
||||||
event_results = set(event_list)
|
event_results = set(event_list)
|
||||||
|
|
||||||
front = event_list
|
# We want to make sure that we do a breadth-first, "depth" ordered
|
||||||
|
# search.
|
||||||
|
|
||||||
query = (
|
query = (
|
||||||
"SELECT prev_event_id FROM event_edges "
|
"SELECT depth, prev_event_id FROM event_edges"
|
||||||
"WHERE room_id = ? AND event_id = ? "
|
" INNER JOIN events"
|
||||||
"LIMIT ?"
|
" ON prev_event_id = events.event_id"
|
||||||
|
" AND event_edges.room_id = events.room_id"
|
||||||
|
" WHERE event_edges.room_id = ? AND event_edges.event_id = ?"
|
||||||
|
" LIMIT ?"
|
||||||
)
|
)
|
||||||
|
|
||||||
# We iterate through all event_ids in `front` to select their previous
|
queue = PriorityQueue()
|
||||||
# events. These are dumped in `new_front`.
|
|
||||||
# We continue until we reach the limit *or* new_front is empty (i.e.,
|
|
||||||
# we've run out of things to select
|
|
||||||
while front and len(event_results) < limit:
|
|
||||||
|
|
||||||
new_front = []
|
for event_id in event_list:
|
||||||
for event_id in front:
|
txn.execute(
|
||||||
logger.debug(
|
query,
|
||||||
"_backfill_interaction: id=%s",
|
(room_id, event_id, limit - len(event_results))
|
||||||
event_id
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for row in txn.fetchall():
|
||||||
|
queue.put(row)
|
||||||
|
|
||||||
|
while not queue.empty() and len(event_results) < limit:
|
||||||
|
_, event_id = queue.get_nowait()
|
||||||
|
|
||||||
|
event_results.add(event_id)
|
||||||
|
|
||||||
txn.execute(
|
txn.execute(
|
||||||
query,
|
query,
|
||||||
(room_id, event_id, limit - len(event_results))
|
(room_id, event_id, limit - len(event_results))
|
||||||
)
|
)
|
||||||
|
|
||||||
for row in txn.fetchall():
|
for row in txn.fetchall():
|
||||||
logger.debug(
|
queue.put(row)
|
||||||
"_backfill_interaction: got id=%s",
|
|
||||||
*row
|
|
||||||
)
|
|
||||||
new_front.append(row[0])
|
|
||||||
|
|
||||||
front = new_front
|
|
||||||
event_results += new_front
|
|
||||||
|
|
||||||
return self._get_events_txn(txn, event_results)
|
return self._get_events_txn(txn, event_results)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user