Having an issue with a service function that syncs a json file to my Dexie IndexedDB database. I keep encountering the following error when starting the transaction:
Unhandled rejection: TransactionInactiveError: Transaction has already completed or failed
./node_modules/dexie/dist/dexie.mjs/Transaction.prototype._promise@http://localhost:9000/dist/bundle.js:4876:30
./node_modules/dexie/dist/dexie.mjs/Dexie.prototype._transaction@http://localhost:9000/dist/bundle.js:6488:35
./node_modules/dexie/dist/dexie.mjs/Dexie.prototype.transaction@http://localhost:9000/dist/bundle.js:6438:34
updateEDSMSector/<@http://localhost:9000/dist/bundle.js:169098:26
...
...
The error occurs right after the
console.log('extracted json', json);
statement (with the next console.log not executing). I am unsure of what the problem might be and would appreciate any guidance on how to debug this issue.
static async updateEDSMSector(sector_number: number[], db: EDSMLayerDB) {
const sector = await db.sectors.where('sector_number').equals(sector_number).first();
console.log("Checking for EDSM updates for sector", sector);
const updatedDate = sector.updatedDate;
const [sx, sy, sz] = sector.sector_number;
const jsonFilename = `edsm/${sx}/${sy}/${sx}_${sy}_${sz}.json.gz`;
let res = await fetch(jsonFilename, {
cache: 'no-cache',
method: 'HEAD',
});
const lastModified = new Date(res.headers.get('Last-Modified'));
console.log('updatedDate', updatedDate, 'lastModified', lastModified);
if (!updatedDate || new Date(updatedDate) < lastModified) {
res = await fetch(jsonFilename, {
cache: 'no-cache',
method: 'GET',
});
console.log('importing data');
const json = JSON.parse(ungzip(new Uint8Array(await res.arrayBuffer()),
{to: 'string'}));
console.log('extracted json', json);
await db.transaction('rw', db.sectors, db.systems, async () => {
console.log('started transaction');
await db.systems.where('sector').equals(sector.sector_number).delete();
console.log('deleted old data');
for (const system of json) {
const {coords, ...rest} = system;
const val = {...rest, ...coords};
await db.systems.add(val);
};
console.log('Added systems');
sector.updatedDate = new Date();
await db.sectors.put(sector);
});
console.log('Finished adding system data');
} else {
console.log('Systems for sector', sector, 'already up-to-date.');
}
}