rename Gap/SyncPersistence to Writer, in line with TimelineReader

This commit is contained in:
Bruno Windels 2019-06-01 15:40:21 +02:00
parent 784588440c
commit fa4efe0132
4 changed files with 11 additions and 11 deletions

View file

@ -1,6 +1,6 @@
import EventEmitter from "../../EventEmitter.js";
import RoomSummary from "./summary.js";
import SyncPersister from "./timeline/persistence/SyncPersister.js";
import SyncWriter from "./timeline/persistence/SyncWriter.js";
import Timeline from "./timeline/Timeline.js";
import FragmentIdComparer from "./timeline/FragmentIdComparer.js";
@ -12,14 +12,14 @@ export default class Room extends EventEmitter {
this._hsApi = hsApi;
this._summary = new RoomSummary(roomId);
this._fragmentIdComparer = new FragmentIdComparer([]);
this._syncPersister = new SyncPersister({roomId, storage, fragmentIdComparer: this._fragmentIdComparer});
this._syncWriter = new SyncWriter({roomId, storage, fragmentIdComparer: this._fragmentIdComparer});
this._emitCollectionChange = emitCollectionChange;
this._timeline = null;
}
persistSync(roomResponse, membership, txn) {
const summaryChanged = this._summary.applySync(roomResponse, membership, txn);
const newTimelineEntries = this._syncPersister.persistSync(roomResponse, txn);
const newTimelineEntries = this._syncWriter.writeSync(roomResponse, txn);
return {summaryChanged, newTimelineEntries};
}
@ -35,7 +35,7 @@ export default class Room extends EventEmitter {
load(summary, txn) {
this._summary.load(summary);
return this._syncPersister.load(txn);
return this._syncWriter.load(txn);
}
get name() {

View file

@ -1,6 +1,6 @@
import { ObservableArray } from "../../../observable/index.js";
import sortedIndex from "../../../utils/sortedIndex.js";
import GapPersister from "./persistence/GapPersister.js";
import GapWriter from "./persistence/GapWriter.js";
import TimelineReader from "./persistence/TimelineReader.js";
export default class Timeline {
@ -41,12 +41,12 @@ export default class Timeline {
limit: amount
});
const gapPersister = new GapPersister({
const gapWriter = new GapWriter({
roomId: this._roomId,
storage: this._storage,
fragmentIdComparer: this._fragmentIdComparer
});
const newEntries = await gapPersister.persistFragmentFill(fragmentEntry, response);
const newEntries = await gapWriter.writerFragmentFill(fragmentEntry, response);
// find where to replace existing gap with newEntries by doing binary search
const gapIdx = sortedIndex(this._entriesList.array, fragmentEntry, (fragmentEntry, entry) => {
return fragmentEntry.compare(entry);

View file

@ -2,7 +2,7 @@ import EventKey from "../EventKey.js";
import EventEntry from "../entries/EventEntry.js";
import {createEventEntry, directionalAppend} from "./common.js";
export default class GapPersister {
export default class GapWriter {
constructor({roomId, storage, fragmentIdComparer}) {
this._roomId = roomId;
this._storage = storage;
@ -71,7 +71,7 @@ export default class GapPersister {
txn.timelineFragments.set(fragmentEntry.fragment);
}
async persistFragmentFill(fragmentEntry, response) {
async writeFragmentFill(fragmentEntry, response) {
const {fragmentId, direction} = fragmentEntry;
// assuming that chunk is in chronological order when backwards too?
const {chunk, start, end} = response;

View file

@ -3,7 +3,7 @@ import EventEntry from "../entries/EventEntry.js";
import FragmentBoundaryEntry from "../entries/FragmentBoundaryEntry.js";
import {createEventEntry} from "./common.js";
export default class SyncPersister {
export default class SyncWriter {
constructor({roomId, storage, fragmentIdComparer}) {
this._roomId = roomId;
this._storage = storage;
@ -65,7 +65,7 @@ export default class SyncPersister {
return {oldFragment, newFragment};
}
async persistSync(roomResponse, txn) {
async writeSync(roomResponse, txn) {
const entries = [];
if (!this._lastLiveKey) {
// means we haven't synced this room yet (just joined or did initial sync)