fix filling gaps with overlapping events

although event order remains wrong, as events are reversed.
step before removing premature optimization, so it's in the git
commit log
This commit is contained in:
Bruno Windels 2019-06-03 00:11:29 +02:00
parent c9aaa18151
commit 0407829b26

View file

@ -8,15 +8,22 @@ export default class GapWriter {
this._storage = storage;
this._fragmentIdComparer = fragmentIdComparer;
}
// events is in reverse-chronological order (last event comes at index 0) if backwards
async _findOverlappingEvents(fragmentEntry, events, txn) {
const eventIds = events.map(e => e.event_id);
const {direction} = fragmentEntry;
// make it in chronological order, so findFirstOrLastOccurringEventId can
// use it's supposed optimization if event ids sorting order correlates with timeline chronology.
// premature optimization?
if (direction.isBackward) {
events = events.slice().reverse();
}
const eventIds = events.map(e => e.event_id);
const findLast = direction.isBackward;
let nonOverlappingEvents = events;
let neighbourFragmentEntry;
const neighbourEventId = await txn.timelineEvents.findFirstOrLastOccurringEventId(this._roomId, eventIds, findLast);
if (neighbourEventId) {
console.log("_findOverlappingEvents neighbourEventId", neighbourEventId);
// trim overlapping events
const neighbourEventIndex = events.findIndex(e => e.event_id === neighbourEventId);
const start = direction.isBackward ? neighbourEventIndex + 1 : 0;
@ -24,10 +31,13 @@ export default class GapWriter {
nonOverlappingEvents = events.slice(start, end);
// get neighbour fragment to link it up later on
const neighbourEvent = await txn.timelineEvents.getByEventId(this._roomId, neighbourEventId);
const neighbourFragment = await txn.timelineFragments.get(neighbourEvent.fragmentId);
console.log("neighbourEvent", {neighbourEvent, start, end, nonOverlappingEvents, events, neighbourEventIndex});
const neighbourFragment = await txn.timelineFragments.get(this._roomId, neighbourEvent.fragmentId);
neighbourFragmentEntry = fragmentEntry.createNeighbourEntry(neighbourFragment);
}
console.log("_findOverlappingEvents events", events, nonOverlappingEvents);
return {nonOverlappingEvents, neighbourFragmentEntry};
}