define storage keys to be 32bit for idb / web platform

as a preparation to serialize the eventIndex and fragmentId
as a 8 character string, part of a concatenated string PK,
as lumia doesn't support array keys.
This commit is contained in:
Bruno Windels 2019-06-26 21:49:42 +02:00
parent ca4361248f
commit 106146660c
6 changed files with 36 additions and 14 deletions

5
src/Platform.js Normal file
View file

@ -0,0 +1,5 @@
// #ifdef PLATFORM_GNOME
// export {default} from "./ui/gnome/GnomePlatform.js";
// #else
export {default} from "./ui/web/WebPlatform.js";
// #endif

View file

@ -1,7 +1,4 @@
const DEFAULT_LIVE_FRAGMENT_ID = 0;
const MIN_EVENT_INDEX = Number.MIN_SAFE_INTEGER + 1;
const MAX_EVENT_INDEX = Number.MAX_SAFE_INTEGER - 1;
const MID_EVENT_INDEX = 0;
import Platform from "../../../Platform.js";
// key for events in the timelineEvents store
export default class EventKey {
@ -12,7 +9,7 @@ export default class EventKey {
nextFragmentKey() {
// could take MIN_EVENT_INDEX here if it can't be paged back
return new EventKey(this.fragmentId + 1, MID_EVENT_INDEX);
return new EventKey(this.fragmentId + 1, Platform.middleStorageKey);
}
nextKeyForDirection(direction) {
@ -32,15 +29,15 @@ export default class EventKey {
}
static get maxKey() {
return new EventKey(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
return new EventKey(Platform.maxStorageKey, Platform.maxStorageKey);
}
static get minKey() {
return new EventKey(Number.MIN_SAFE_INTEGER, Number.MIN_SAFE_INTEGER);
return new EventKey(Platform.minStorageKey, Platform.minStorageKey);
}
static get defaultLiveKey() {
return new EventKey(DEFAULT_LIVE_FRAGMENT_ID, MID_EVENT_INDEX);
return new EventKey(Platform.minStorageKey, Platform.middleStorageKey);
}
toString() {

View file

@ -1,6 +1,7 @@
import BaseEntry from "./BaseEntry.js";
import Direction from "../Direction.js";
import {isValidFragmentId} from "../common.js";
import Platform from "../../../../Platform.js";
export default class FragmentBoundaryEntry extends BaseEntry {
constructor(fragment, isFragmentStart, fragmentIdComparer) {
@ -36,9 +37,9 @@ export default class FragmentBoundaryEntry extends BaseEntry {
get entryIndex() {
if (this.started) {
return Number.MIN_SAFE_INTEGER;
return Platform.minStorageKey;
} else {
return Number.MAX_SAFE_INTEGER;
return Platform.maxStorageKey;
}
}

View file

@ -1,4 +1,5 @@
import EventKey from "../../../room/timeline/EventKey.js";
import Platform from "../../../../Platform.js";
class Range {
constructor(only, lower, upper, lowerOpen, upperOpen) {
@ -19,7 +20,7 @@ class Range {
if (this._lower && !this._upper) {
return IDBKeyRange.bound(
[roomId, this._lower.fragmentId, this._lower.eventIndex],
[roomId, this._lower.fragmentId, EventKey.maxKey.eventIndex],
[roomId, this._lower.fragmentId, Platform.maxStorageKey],
this._lowerOpen,
false
);
@ -28,7 +29,7 @@ class Range {
// also bound as we don't want to move into another roomId
if (!this._lower && this._upper) {
return IDBKeyRange.bound(
[roomId, this._upper.fragmentId, EventKey.minKey.eventIndex],
[roomId, this._upper.fragmentId, Platform.minStorageKey],
[roomId, this._upper.fragmentId, this._upper.eventIndex],
false,
this._upperOpen

View file

@ -1,3 +1,5 @@
import Platform from "../../../../Platform.js";
export default class RoomFragmentStore {
constructor(store) {
this._store = store;
@ -5,8 +7,8 @@ export default class RoomFragmentStore {
_allRange(roomId) {
return IDBKeyRange.bound(
[roomId, Number.MIN_SAFE_INTEGER],
[roomId, Number.MAX_SAFE_INTEGER]
[roomId, Platform.minStorageKey],
[roomId, Platform.maxStorageKey]
);
}

16
src/ui/web/WebPlatform.js Normal file
View file

@ -0,0 +1,16 @@
export default {
get minStorageKey() {
// for indexeddb, we use unsigned 32 bit integers as keys
return 0;
},
get middleStorageKey() {
// for indexeddb, we use unsigned 32 bit integers as keys
return 0x7FFFFFFF;
},
get maxStorageKey() {
// for indexeddb, we use unsigned 32 bit integers as keys
return 0xFFFFFFFF;
},
}