fix some gap fill errors

This commit is contained in:
Bruno Windels 2019-06-02 15:46:24 +02:00
parent d022608a1a
commit bdad0ad86b
3 changed files with 18 additions and 15 deletions

View file

@ -12,14 +12,16 @@ export default class GapTile extends SimpleTile {
// prevent doing this twice // prevent doing this twice
if (!this._loading) { if (!this._loading) {
this._loading = true; this._loading = true;
this._emitUpdate("isLoading"); // this._emitUpdate("isLoading");
try { try {
return await this._timeline.fillGap(this._entry, 10); await this._timeline.fillGap(this._entry, 10);
} catch (err) { } catch (err) {
this._loading = false; console.error(`timeline.fillGap(): ${err.message}:\n${err.stack}`);
this._error = err; this._error = err;
this._emitUpdate("isLoading"); // this._emitUpdate("error");
this._emitUpdate("error"); } finally {
this._loading = false;
// this._emitUpdate("isLoading");
} }
} }
} }

View file

@ -4,11 +4,12 @@ import GapWriter from "./persistence/GapWriter.js";
import TimelineReader from "./persistence/TimelineReader.js"; import TimelineReader from "./persistence/TimelineReader.js";
export default class Timeline { export default class Timeline {
constructor({roomId, storage, closeCallback, fragmentIdComparer}) { constructor({roomId, storage, closeCallback, fragmentIdComparer, hsApi}) {
this._roomId = roomId; this._roomId = roomId;
this._storage = storage; this._storage = storage;
this._closeCallback = closeCallback; this._closeCallback = closeCallback;
this._fragmentIdComparer = fragmentIdComparer; this._fragmentIdComparer = fragmentIdComparer;
this._hsApi = hsApi;
this._entriesList = new SortedArray((a, b) => a.compare(b)); this._entriesList = new SortedArray((a, b) => a.compare(b));
this._timelineReader = new TimelineReader({ this._timelineReader = new TimelineReader({
roomId: this._roomId, roomId: this._roomId,
@ -34,14 +35,13 @@ export default class Timeline {
from: fragmentEntry.token, from: fragmentEntry.token,
dir: fragmentEntry.direction.asApiString(), dir: fragmentEntry.direction.asApiString(),
limit: amount limit: amount
}); }).response();
const gapWriter = new GapWriter({ const gapWriter = new GapWriter({
roomId: this._roomId, roomId: this._roomId,
storage: this._storage, storage: this._storage,
fragmentIdComparer: this._fragmentIdComparer fragmentIdComparer: this._fragmentIdComparer
}); });
const newEntries = await gapWriter.writerFragmentFill(fragmentEntry, response); const newEntries = await gapWriter.writeFragmentFill(fragmentEntry, response);
this._entriesList.setManySorted(newEntries); this._entriesList.setManySorted(newEntries);
} }

View file

@ -47,9 +47,10 @@ export default class GapWriter {
const reducer = direction.isBackward ? Array.prototype.reduceRight : Array.prototype.reduce; const reducer = direction.isBackward ? Array.prototype.reduceRight : Array.prototype.reduce;
reducer.call(events, (key, event, i) => { reducer.call(events, (key, event, i) => {
key = key.nextKeyForDirection(direction); key = key.nextKeyForDirection(direction);
const eventEntry = createEventEntry(key, event); const eventEntry = createEventEntry(key, this._roomId, event);
txn.timelineEvents.insert(eventEntry); txn.timelineEvents.insert(eventEntry);
entries[i] = new EventEntry(eventEntry, this._fragmentIdComparer); entries[i] = new EventEntry(eventEntry, this._fragmentIdComparer);
return key;
}, startKey); }, startKey);
return entries; return entries;
} }
@ -61,7 +62,7 @@ export default class GapWriter {
if (neighbourFragmentEntry) { if (neighbourFragmentEntry) {
fragmentEntry.linkedFragmentId = neighbourFragmentEntry.fragmentId; fragmentEntry.linkedFragmentId = neighbourFragmentEntry.fragmentId;
neighbourFragmentEntry.linkedFragmentId = fragmentEntry.fragmentId; neighbourFragmentEntry.linkedFragmentId = fragmentEntry.fragmentId;
txn.timelineFragments.set(neighbourFragmentEntry.fragment); txn.timelineFragments.update(neighbourFragmentEntry.fragment);
directionalAppend(entries, neighbourFragmentEntry, direction); directionalAppend(entries, neighbourFragmentEntry, direction);
// update fragmentIdComparer here after linking up fragments // update fragmentIdComparer here after linking up fragments
@ -69,7 +70,7 @@ export default class GapWriter {
this._fragmentIdComparer.add(neighbourFragmentEntry.fragment); this._fragmentIdComparer.add(neighbourFragmentEntry.fragment);
} }
fragmentEntry.token = end; fragmentEntry.token = end;
txn.timelineFragments.set(fragmentEntry.fragment); txn.timelineFragments.update(fragmentEntry.fragment);
} }
async writeFragmentFill(fragmentEntry, response) { async writeFragmentFill(fragmentEntry, response) {
@ -92,7 +93,7 @@ export default class GapWriter {
try { try {
// make sure we have the latest fragment from the store // make sure we have the latest fragment from the store
const fragment = await txn.timelineFragments.get(fragmentId); const fragment = await txn.timelineFragments.get(this._roomId, fragmentId);
if (!fragment) { if (!fragment) {
throw new Error(`Unknown fragment: ${fragmentId}`); throw new Error(`Unknown fragment: ${fragmentId}`);
} }
@ -102,12 +103,12 @@ export default class GapWriter {
throw new Error("start is not equal to prev_batch or next_batch"); throw new Error("start is not equal to prev_batch or next_batch");
} }
// find last event in fragment so we get the eventIndex to begin creating keys at // find last event in fragment so we get the eventIndex to begin creating keys at
let lastKey = this._findLastFragmentEventKey(fragmentEntry, txn); let lastKey = await this._findLastFragmentEventKey(fragmentEntry, txn);
// find out if any event in chunk is already present using findFirstOrLastOccurringEventId // find out if any event in chunk is already present using findFirstOrLastOccurringEventId
const { const {
nonOverlappingEvents, nonOverlappingEvents,
neighbourFragmentEntry neighbourFragmentEntry
} = this._findOverlappingEvents(fragmentEntry, chunk, txn); } = await this._findOverlappingEvents(fragmentEntry, chunk, txn);
// create entries for all events in chunk, add them to entries // create entries for all events in chunk, add them to entries
entries = this._storeEvents(nonOverlappingEvents, lastKey, direction, txn); entries = this._storeEvents(nonOverlappingEvents, lastKey, direction, txn);