Skip to content

Commit

Permalink
cleanup, improve clarity in some places
Browse files Browse the repository at this point in the history
  • Loading branch information
djahandarie committed Dec 17, 2024
1 parent 4ab4ad4 commit 2c5f42d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
1 change: 0 additions & 1 deletion ext/js/comm/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ export class API {
log.error('no backend port available');
return;
}
// console.log('go', this._backendPort, action, params, transferables);
this._backendPort.postMessage({action, params}, transferables);
} else {
void navigator.serviceWorker.ready.then((swr) => {
Expand Down
14 changes: 5 additions & 9 deletions ext/js/dictionary/dictionary-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ export class DictionaryDatabase {
}

/**
*
* do upgrades for the IndexedDB schema (basically limited to adding new stores when needed)
*/
async prepare() {
// do not do upgrades in web workers as they are considered to be children of the main thread and are not responsible for database upgrades
const upgrade = self.constructor.name !== 'Window' ?
null :
const isWorker = self.constructor.name !== 'Window';
const upgrade =
/** @type {import('database').StructureDefinition<import('dictionary-database').ObjectStoreName>[]?} */
([
/** @type {import('database').StructureDefinition<import('dictionary-database').ObjectStoreName>} */
Expand Down Expand Up @@ -155,11 +155,11 @@ export class DictionaryDatabase {
await this._db.open(
this._dbName,
60,
upgrade,
isWorker ? null : upgrade,
);

// when we are not a worker ourselves, create a worker which is basically just a wrapper around this class, which we can use to offload some functions to
if (self.constructor.name === 'Window') {
if (!isWorker) {
this._worker = new Worker('/js/dictionary/dictionary-database-worker-main.js', {type: 'module'});
this._worker.addEventListener('error', (event) => {
log.log('Worker terminated with error:', event);
Expand Down Expand Up @@ -418,10 +418,7 @@ export class DictionaryDatabase {

/** @type {import('dictionary-database').FindPredicate<import('dictionary-database').MediaRequest, import('dictionary-database').MediaDataArrayBufferContent>} */
const predicate = (row, item) => (row.dictionary === item.dictionary);
// performance.mark('drawMedia:findMultiBulk:start');
const results = await this._findMultiBulk('media', ['path'], groupedItemsArray, this._createOnlyQuery5, predicate, this._createDrawMediaBind);
// performance.mark('drawMedia:findMultiBulk:end');
// performance.measure('drawMedia:findMultiBulk', 'drawMedia:findMultiBulk:start', 'drawMedia:findMultiBulk:end');

// move all svgs to front to have a hotter loop
results.sort((a, _b) => (a.mediaType === 'image/svg+xml' ? -1 : 1));
Expand Down Expand Up @@ -637,7 +634,6 @@ export class DictionaryDatabase {
}
};
performance.mark('findMultiBulk:getAll:start');
// console.log('?');
for (let i = 0; i < itemCount; ++i) {
const item = items[i];
const query = createQuery(item);
Expand Down

0 comments on commit 2c5f42d

Please sign in to comment.