forked from mystiq/hydrogen-web
log storage migration
This commit is contained in:
parent
0c05e97465
commit
fa555bedf0
3 changed files with 15 additions and 11 deletions
|
@ -204,7 +204,7 @@ export class SessionContainer {
|
|||
reconnector: this._reconnector,
|
||||
});
|
||||
this._sessionId = sessionInfo.id;
|
||||
this._storage = await this._platform.storageFactory.create(sessionInfo.id);
|
||||
this._storage = await this._platform.storageFactory.create(sessionInfo.id, log);
|
||||
// no need to pass access token to session
|
||||
const filteredSessionInfo = {
|
||||
id: sessionInfo.id,
|
||||
|
|
|
@ -21,8 +21,9 @@ import { schema } from "./schema.js";
|
|||
import { detectWebkitEarlyCloseTxnBug } from "./quirks.js";
|
||||
|
||||
const sessionName = sessionId => `hydrogen_session_${sessionId}`;
|
||||
const openDatabaseWithSessionId = function(sessionId, idbFactory) {
|
||||
return openDatabase(sessionName(sessionId), createStores, schema.length, idbFactory);
|
||||
const openDatabaseWithSessionId = function(sessionId, idbFactory, log) {
|
||||
const create = (db, txn, oldVersion, version) => createStores(db, txn, oldVersion, version, log);
|
||||
return openDatabase(sessionName(sessionId), create, schema.length, idbFactory);
|
||||
}
|
||||
|
||||
async function requestPersistedStorage() {
|
||||
|
@ -49,7 +50,7 @@ export class StorageFactory {
|
|||
this._IDBKeyRange = IDBKeyRange;
|
||||
}
|
||||
|
||||
async create(sessionId) {
|
||||
async create(sessionId, log) {
|
||||
await this._serviceWorkerHandler?.preventConcurrentSessionAccess(sessionId);
|
||||
requestPersistedStorage().then(persisted => {
|
||||
// Firefox lies here though, and returns true even if the user denied the request
|
||||
|
@ -59,7 +60,7 @@ export class StorageFactory {
|
|||
});
|
||||
|
||||
const hasWebkitEarlyCloseTxnBug = await detectWebkitEarlyCloseTxnBug(this._idbFactory);
|
||||
const db = await openDatabaseWithSessionId(sessionId, this._idbFactory);
|
||||
const db = await openDatabaseWithSessionId(sessionId, this._idbFactory, log);
|
||||
return new Storage(db, this._IDBKeyRange, hasWebkitEarlyCloseTxnBug);
|
||||
}
|
||||
|
||||
|
@ -80,10 +81,12 @@ export class StorageFactory {
|
|||
}
|
||||
}
|
||||
|
||||
async function createStores(db, txn, oldVersion, version) {
|
||||
async function createStores(db, txn, oldVersion, version, log) {
|
||||
const startIdx = oldVersion || 0;
|
||||
return log.wrap({l: "storage migration", oldVersion, version}, async log => {
|
||||
for(let i = startIdx; i < version; ++i) {
|
||||
await log.wrap(`v${i + 1}`, log => schema[i](db, txn, log));
|
||||
}
|
||||
});
|
||||
|
||||
for(let i = startIdx; i < version; ++i) {
|
||||
await schema[i](db, txn);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@ limitations under the License.
|
|||
|
||||
import {FDBFactory, FDBKeyRange} from "../../lib/fake-indexeddb/index.js";
|
||||
import {StorageFactory} from "../matrix/storage/idb/StorageFactory.js";
|
||||
import {NullLogItem} from "../logging/NullLogger.js";
|
||||
|
||||
export function createMockStorage() {
|
||||
return new StorageFactory(null, new FDBFactory(), FDBKeyRange).create(1);
|
||||
}
|
||||
return new StorageFactory(null, new FDBFactory(), FDBKeyRange).create(1, new NullLogItem());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue