From 61536a09fe5b9277d03e5d020dd52b14aa74cb32 Mon Sep 17 00:00:00 2001 From: Emiliano Heyns Date: Fri, 1 Mar 2024 19:00:36 +0100 Subject: [PATCH 1/6] add logging --- content/key-manager.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/content/key-manager.ts b/content/key-manager.ts index 1793dec47..3f128b008 100644 --- a/content/key-manager.ts +++ b/content/key-manager.ts @@ -555,6 +555,7 @@ export const KeyManager = new class _KeyManager { public update(item: ZoteroItem, current?: CitekeyRecord): string { if (item.isFeedItem || !item.isRegularItem()) return null + log.debug('2797: update', item.id) current = current || blink.first(this.keys, { where: { itemID: item.id } }) @@ -562,6 +563,7 @@ export const KeyManager = new class _KeyManager { if (current && (current.pinned || !this.autopin.enabled) && (current.pinned === proposed.pinned) && (current.citationKey === proposed.citationKey)) return current.citationKey + log.debug('2797: update', item.id, 'to', proposed) if (current) { current.pinned = proposed.pinned current.citationKey = proposed.citationKey From ce8c799ad81e2129124482f96357fcd13fbe05d9 Mon Sep 17 00:00:00 2001 From: Emiliano Heyns Date: Mon, 4 Mar 2024 22:26:40 +0100 Subject: [PATCH 2/6] log missing keys --- content/key-manager.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/content/key-manager.ts b/content/key-manager.ts index 3f128b008..2339e0725 100644 --- a/content/key-manager.ts +++ b/content/key-manager.ts @@ -539,6 +539,7 @@ export const KeyManager = new class _KeyManager { // generate keys for entries that don't have them yet const progress = new Progress(missing.length, 'Assigning citation keys') + log.debug('2797:', missing.length, 'missing a key') for (const itemID of missing) { try { this.update(await getItemsAsync(itemID)) From bc4650e76a3c07ced478169a246e9c283258f879 Mon Sep 17 00:00:00 2001 From: Emiliano Heyns Date: Sat, 9 Mar 2024 12:14:05 +0100 Subject: [PATCH 3/6] storing vs enabled --- content/ErrorReport.ts | 8 ++++---- content/better-bibtex.ts | 2 +- content/translators.ts | 2 +- setup/loaders/trace.js | 2 +- submodules/babel | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/content/ErrorReport.ts b/content/ErrorReport.ts index 6fdbf3fe3..43a579ddd 100644 --- a/content/ErrorReport.ts +++ b/content/ErrorReport.ts @@ -95,7 +95,7 @@ export class ErrorReport { if (wizard.onLastPage) wizard.canRewind = false else if (wizard.pageIndex === 0) wizard.canRewind = false - else if (wizard.pageIndex === 1 && Zotero.Debug.enabled) wizard.canRewind = false + else if (wizard.pageIndex === 1 && Zotero.Debug.storing) wizard.canRewind = false else wizard.canRewind = true } @@ -194,7 +194,7 @@ export class ErrorReport { wizard.getPageById('page-send').addEventListener('pageshow', () => { this.send().catch(err => log.debug('could not send debug log:', err)) }) wizard.getPageById('page-done').addEventListener('pageshow', this.show.bind(this)) - if (Zotero.Debug.enabled) wizard.pageIndex = 1 + wizard.pageIndex = Zotero.Debug.storing ? 1 : 0 const continueButton = wizard.getButton('next') continueButton.disabled = true @@ -306,8 +306,8 @@ export class ErrorReport { } } - info += `Zotero.Debug.enabled: ${Zotero.Debug.enabled}\n` - info += `Zotero.Debug.enabled at start: ${Zotero.BetterBibTeX.debugEnabledAtStart}\n` + info += `Zotero.Debug.storing: ${Zotero.Debug.storing}\n` + info += `Zotero.Debug.storing at start: ${Zotero.BetterBibTeX.debugEnabledAtStart}\n` return info } diff --git a/content/better-bibtex.ts b/content/better-bibtex.ts index eea6a4793..eb82b2a2b 100644 --- a/content/better-bibtex.ts +++ b/content/better-bibtex.ts @@ -584,7 +584,7 @@ export class BetterBibTeX { public generateCSLJSON = generateCSLJSON constructor() { - this.debugEnabledAtStart = Zotero.Prefs.get('debug.store') || Zotero.Debug.enabled + this.debugEnabledAtStart = Zotero.Prefs.get('debug.store') || Zotero.Debug.storing if (Zotero.isWin && !is7) Zotero.Debug.addListener(this.logListener.bind(this)) } diff --git a/content/translators.ts b/content/translators.ts index 2fa885039..9f9715f09 100644 --- a/content/translators.ts +++ b/content/translators.ts @@ -283,7 +283,7 @@ export const Translators = new class { // eslint-disable-line @typescript-eslint translator: translator.label, output: job.path || '', - debugEnabled: !!Zotero.Debug.enabled, + debugEnabled: !!Zotero.Debug.storing, } let items: any[] = [] diff --git a/setup/loaders/trace.js b/setup/loaders/trace.js index 72b97d9ac..384d9226f 100644 --- a/setup/loaders/trace.js +++ b/setup/loaders/trace.js @@ -1,5 +1,5 @@ ; -// if (typeof Zotero !== 'undefined' && Zotero.Debug) Zotero.Debug.enabled = true +// if (typeof Zotero !== 'undefined' && Zotero.Debug) Zotero.Debug.setStore(true) const __estrace = { hold: '', diff --git a/submodules/babel b/submodules/babel index 4e9e240a0..e25bf9bd6 160000 --- a/submodules/babel +++ b/submodules/babel @@ -1 +1 @@ -Subproject commit 4e9e240a04a3c01497181e039d61f2f85aede5f3 +Subproject commit e25bf9bd686605211927b74a69e1b55ede9f315f From e3757b4239cb7631e4ce36b842556115f6822350 Mon Sep 17 00:00:00 2001 From: Emiliano Heyns Date: Sat, 9 Mar 2024 15:22:25 +0100 Subject: [PATCH 4/6] dynamic queries --- content/key-manager.ts | 55 ++++++++++++------------------------------ 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/content/key-manager.ts b/content/key-manager.ts index 8f84977d1..49f41b9ac 100644 --- a/content/key-manager.ts +++ b/content/key-manager.ts @@ -91,14 +91,6 @@ export const KeyManager = new class _KeyManager { }) private unwatch: UnwatchCallback[] = [] - public query: { - field: { extra?: number, title?: number } - type: { - note?: number - attachment?: number - annotation?: number - } - } public autopin: Scheduler = new Scheduler('autoPinDelay', 1000) private started = false @@ -252,19 +244,6 @@ export const KeyManager = new class _KeyManager { await kuroshiro.init() chinese.init() - this.query = { - field: {}, - type: {}, - } - - for (const type of await ZoteroDB.queryAsync('select itemTypeID, typeName from itemTypes')) { // 1 = attachment, 14 = note - this.query.type[type.typeName] = type.itemTypeID - } - - for (const field of await ZoteroDB.queryAsync('select fieldID, fieldName from fields')) { - this.query.field[field.fieldName] = field.fieldID - } - Formatter.update([Preference.citekeyFormat]) await this.start() @@ -467,17 +446,19 @@ export const KeyManager = new class _KeyManager { let missing: number[] await Zotero.DB.executeTransaction(async () => { - const items = `BBTITEMS${Zotero.Utilities.generateObjectKey()}` - await ZoteroDB.queryAsync(` - CREATE TEMPORARY TABLE ${items} - AS - SELECT itemID, key as itemKey, libraryID - FROM items - WHERE itemID NOT IN (SELECT itemID FROM deletedItems) - AND itemTypeID NOT IN (${this.query.type.attachment}, ${this.query.type.note}, ${this.query.type.annotation || this.query.type.note}) - AND itemID NOT IN (SELECT itemID from feedItems) - `) - await Zotero.DB.queryAsync(`DELETE FROM betterbibtex.citationkey WHERE itemID NOT IN (SELECT itemID FROM ${items})`) + const $items = ` + WITH _items AS ( + SELECT items.itemID, items.key as itemKey, items.libraryID, extra.value AS extra + FROM items + LEFT JOIN itemData extraField ON extraField.itemID = items.itemID AND extraField.fieldID IN (SELECT fieldID FROM fields WHERE fieldName = 'extra') + LEFT JOIN itemDataValues extra ON extra.valueID = extraField.valueID + WHERE items.itemID NOT IN (SELECT itemID FROM deletedItems) + AND items.itemTypeID NOT IN (SELECT itemTypeID FROM itemTypes WHERE typeName IN ('attachment', 'note', 'annotation')) + AND items.itemID NOT IN (SELECT itemID from feedItems) + ) + ` + + await ZoteroDB.queryAsync(`${$items} DELETE FROM betterbibtex.citationkey WHERE itemID NOT IN (SELECT itemID FROM _items)`) const keys: Map = new Map let key: CitekeyRecord @@ -494,12 +475,7 @@ export const KeyManager = new class _KeyManager { } let pinned: string - for (const item of (await ZoteroDB.queryAsync(` - SELECT item.itemID, item.itemKey, item.libraryID, extra.value as extra - FROM ${items} item - LEFT JOIN itemData extraField ON extraField.itemID = item.itemID AND extraField.fieldID = ${this.query.field.extra} - LEFT JOIN itemDataValues extra ON extra.valueID = extraField.valueID - `))) { + for (const item of (await ZoteroDB.queryAsync(`${$items} SELECT itemID, itemKey, libraryID, extra FROM _items`))) { pinned = getKey(item.extra) if (pinned) { keys.set(item.itemID, lc({ itemID: item.itemID, itemKey: item.itemKey, libraryID: item.libraryID, citationKey: pinned, pinned: true })) @@ -511,8 +487,7 @@ export const KeyManager = new class _KeyManager { blink.insertMany(this.keys, [...keys.values()]) - missing = await Zotero.DB.columnQueryAsync(`SELECT itemID FROM ${items} WHERE itemID NOT IN (SELECT itemID from betterbibtex.citationkey)`) - await Zotero.DB.queryAsync(`DROP TABLE temp.${items}`) + missing = await ZoteroDB.columnQueryAsync(`${$items} SELECT itemID FROM _items WHERE itemID NOT IN (SELECT itemID from betterbibtex.citationkey)`) }) this.unwatch = [ From e097f329dc17081e3c7f53aeb8b4889288bbaa32 Mon Sep 17 00:00:00 2001 From: Emiliano Heyns Date: Sat, 9 Mar 2024 15:22:57 +0100 Subject: [PATCH 5/6] upgrades --- package-lock.json | 62 ++++++++++++++++++++++----------------------- package.json | 10 ++++---- submodules/biblatex | 2 +- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4e67d7e87..4162fa8df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,7 +46,7 @@ "pinyin": "^3.1.0", "punycode2": "^1.0.1", "puqeue": "^1.1.4", - "remeda": "^1.46.2", + "remeda": "^1.47.0", "sprintf-js": "^1.1.3", "tar-js": "^0.3.0", "text-title-case": "^1.0.2", @@ -62,7 +62,7 @@ "@retorquere/zotero-sync": "^1.0.27", "@types/bluebird": "^3.5.42", "@types/lokijs": "^1.5.14", - "@types/node": "^20.11.24", + "@types/node": "^20.11.25", "@xmldom/xmldom": "^0.8.10", "ajv-keywords": "^5.1.0", "archiver": "^7.0.0", @@ -113,8 +113,8 @@ "process": "^0.11.10", "properties-reader": "^2.3.0", "pug": "^3.0.2", - "putout": "^35.6.0", - "recast": "^0.23.5", + "putout": "^35.7.1", + "recast": "^0.23.6", "regenerate": "^1.4.2", "rimraf": "^5.0.5", "shelljs": "^0.8.5", @@ -122,7 +122,7 @@ "string-template": "^1.0.0", "ts-node": "^10.9.2", "tslib": "^2.6.2", - "typescript": "^5.3.3", + "typescript": "^5.4.2", "unicode-11.0.0": "^0.7.8", "unicode2latex": "^5.0.16", "uri-templates": "^0.2.0", @@ -2987,15 +2987,15 @@ } }, "node_modules/@putout/plugin-remove-empty": { - "version": "11.0.0", - "resolved": "https://registry.npmjs.org/@putout/plugin-remove-empty/-/plugin-remove-empty-11.0.0.tgz", - "integrity": "sha512-bKcMC03xKfTiwcKrq4IvXgmeFQSYAhXILyLLHA5dntbqws091DjXnSje5AQ26DRAY6IXZgI3R5aBs9Ql7kOV8Q==", + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/@putout/plugin-remove-empty/-/plugin-remove-empty-12.1.0.tgz", + "integrity": "sha512-kUgGzVBKKe8mR1bQUtUjVzTIdlh9j7KlZtMKCx7Yt2uZNbwQnscbuVlEYQfc7YyqGnWops64Si2YyELoEwil/A==", "dev": true, "engines": { - "node": ">=16" + "node": ">=18" }, "peerDependencies": { - "putout": ">=33" + "putout": ">=35" } }, "node_modules/@putout/plugin-remove-iife": { @@ -3083,15 +3083,15 @@ } }, "node_modules/@putout/plugin-remove-unused-variables": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@putout/plugin-remove-unused-variables/-/plugin-remove-unused-variables-8.1.0.tgz", - "integrity": "sha512-taSNc63WoG05vjtS686erJapMx2Iof/EjHo4B4lIoIW0sOIpMTIk8Ir63mehmM4Hu+XOeX9m5XzsSgSDlcn0Yw==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@putout/plugin-remove-unused-variables/-/plugin-remove-unused-variables-9.0.0.tgz", + "integrity": "sha512-9J8enM2DAEzQMW5zaUThTz2yfceUTkSPmlizhHzXgaod+lBtOBtauIyDaYFaRSO+H21pWcMU1ofmW8C6xda8qA==", "dev": true, "engines": { "node": ">=18" }, "peerDependencies": { - "putout": ">=34" + "putout": ">=35" } }, "node_modules/@putout/plugin-remove-useless-arguments": { @@ -4057,9 +4057,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.11.24", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.24.tgz", - "integrity": "sha512-Kza43ewS3xoLgCEpQrsT+xRo/EJej1y0kVYGiLFE1NEODXGzTfwiC6tXTLMQskn1X4/Rjlh0MQUvx9W+L9long==", + "version": "20.11.25", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.25.tgz", + "integrity": "sha512-TBHyJxk2b7HceLVGFcpAUjsa5zIdsPWlR6XHfyGzd0SFu+/NFgQgMAl96MSDZgQDvJAvV6BKsFOrt6zIL09JDw==", "dependencies": { "undici-types": "~5.26.4" } @@ -12277,9 +12277,9 @@ "integrity": "sha512-EkCRMV2w15w+9wylcpabacKK9VvTRX3TvhVQJBwIk4ThvllI2M6RlvdEZvJLhxsxy4x8IEDZneQhlGU0Pk5keg==" }, "node_modules/putout": { - "version": "35.6.0", - "resolved": "https://registry.npmjs.org/putout/-/putout-35.6.0.tgz", - "integrity": "sha512-/W1EVmCJVHPYYIZAWCqyoJwCycZdcl5/PFTu/MINIloMImh48SmCcFf2mv233YOtOfc7IT2Dud+vkCiWcWhMZA==", + "version": "35.7.1", + "resolved": "https://registry.npmjs.org/putout/-/putout-35.7.1.tgz", + "integrity": "sha512-sPtPJobi5rrKZCgQz4w8iMiKMZaL89Sv50mKcf/KQYY0ujsXKJ9b+vrGhwwGDo0PbxHa9ms6Yc57V5twk3TvFQ==", "dev": true, "dependencies": { "@putout/babel": "^2.0.0", @@ -12370,7 +12370,7 @@ "@putout/plugin-remove-debugger": "^7.0.0", "@putout/plugin-remove-duplicate-case": "^3.0.0", "@putout/plugin-remove-duplicate-keys": "^5.0.0", - "@putout/plugin-remove-empty": "^11.0.0", + "@putout/plugin-remove-empty": "^12.0.0", "@putout/plugin-remove-iife": "^4.0.0", "@putout/plugin-remove-nested-blocks": "^6.0.0", "@putout/plugin-remove-unreachable-code": "^1.0.0", @@ -12378,7 +12378,7 @@ "@putout/plugin-remove-unused-expressions": "^8.0.0", "@putout/plugin-remove-unused-for-of-variables": "^3.0.0", "@putout/plugin-remove-unused-private-fields": "^2.0.0", - "@putout/plugin-remove-unused-variables": "^8.0.0", + "@putout/plugin-remove-unused-variables": "^9.0.0", "@putout/plugin-remove-useless-arguments": "^8.0.0", "@putout/plugin-remove-useless-array": "^1.0.0", "@putout/plugin-remove-useless-array-constructor": "^2.0.0", @@ -12573,9 +12573,9 @@ } }, "node_modules/recast": { - "version": "0.23.5", - "resolved": "https://registry.npmjs.org/recast/-/recast-0.23.5.tgz", - "integrity": "sha512-M67zIddJiwXdfPQRYKJ0qZO1SLdH1I0hYeb0wzxA+pNOvAZiQHulWzuk+fYsEWRQ8VfZrgjyucqsCOtCyM01/A==", + "version": "0.23.6", + "resolved": "https://registry.npmjs.org/recast/-/recast-0.23.6.tgz", + "integrity": "sha512-9FHoNjX1yjuesMwuthAmPKabxYQdOgihFYmT5ebXfYGBcnqXZf3WOVz+5foEZ8Y83P4ZY6yQD5GMmtV+pgCCAQ==", "dev": true, "dependencies": { "ast-types": "^0.16.1", @@ -13857,9 +13857,9 @@ } }, "node_modules/remeda": { - "version": "1.46.2", - "resolved": "https://registry.npmjs.org/remeda/-/remeda-1.46.2.tgz", - "integrity": "sha512-ZpC0t0sAKX+ROyc6tEkbwLBLiURdEgcyDkSTO+CC04CNAsc11z+zjVXZLlAmGHustn4Wo+eAu00OVMqnUj1aOw==" + "version": "1.47.0", + "resolved": "https://registry.npmjs.org/remeda/-/remeda-1.47.0.tgz", + "integrity": "sha512-NhB81y1itYfqF4AYnZW5nq/ukkVtuWrEmmowkkF6MSjSdjiQpYo0khK/h4mNSWjZX50WZHOU5sX80Bd2mw2RRQ==" }, "node_modules/remove-blank-lines": { "version": "1.4.1", @@ -15716,9 +15716,9 @@ } }, "node_modules/typescript": { - "version": "5.3.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", - "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "version": "5.4.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.2.tgz", + "integrity": "sha512-+2/g0Fds1ERlP6JsakQQDXjZdZMM+rqpamFZJEKh4kwTIn3iDkgKtby0CeNd5ATNZ4Ry1ax15TMx0W2V+miizQ==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index 4d9168082..484c832c1 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "pinyin": "^3.1.0", "punycode2": "^1.0.1", "puqeue": "^1.1.4", - "remeda": "^1.46.2", + "remeda": "^1.47.0", "sprintf-js": "^1.1.3", "tar-js": "^0.3.0", "text-title-case": "^1.0.2", @@ -116,7 +116,7 @@ "@retorquere/zotero-sync": "^1.0.27", "@types/bluebird": "^3.5.42", "@types/lokijs": "^1.5.14", - "@types/node": "^20.11.24", + "@types/node": "^20.11.25", "@xmldom/xmldom": "^0.8.10", "ajv-keywords": "^5.1.0", "archiver": "^7.0.0", @@ -167,8 +167,8 @@ "process": "^0.11.10", "properties-reader": "^2.3.0", "pug": "^3.0.2", - "putout": "^35.6.0", - "recast": "^0.23.5", + "putout": "^35.7.1", + "recast": "^0.23.6", "regenerate": "^1.4.2", "rimraf": "^5.0.5", "shelljs": "^0.8.5", @@ -176,7 +176,7 @@ "string-template": "^1.0.0", "ts-node": "^10.9.2", "tslib": "^2.6.2", - "typescript": "^5.3.3", + "typescript": "^5.4.2", "unicode-11.0.0": "^0.7.8", "unicode2latex": "^5.0.16", "uri-templates": "^0.2.0", diff --git a/submodules/biblatex b/submodules/biblatex index 9f2b0ff3a..70cad39d2 160000 --- a/submodules/biblatex +++ b/submodules/biblatex @@ -1 +1 @@ -Subproject commit 9f2b0ff3ae8fd34dc114d87fa02a828535a21b25 +Subproject commit 70cad39d271076c39fc2239cad17a8e13ebac834 From d695874c8fc5b70b2d853446cdedecf61e753e45 Mon Sep 17 00:00:00 2001 From: Emiliano Heyns Date: Sat, 9 Mar 2024 15:23:28 +0100 Subject: [PATCH 6/6] remove logging --- content/key-manager.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/content/key-manager.ts b/content/key-manager.ts index 49f41b9ac..8d2918613 100644 --- a/content/key-manager.ts +++ b/content/key-manager.ts @@ -514,7 +514,6 @@ export const KeyManager = new class _KeyManager { // generate keys for entries that don't have them yet const progress = new Progress(missing.length, 'Assigning citation keys') - log.debug('2797:', missing.length, 'missing a key') for (const itemID of missing) { try { this.update(await getItemsAsync(itemID)) @@ -531,7 +530,6 @@ export const KeyManager = new class _KeyManager { public update(item: ZoteroItem, current?: CitekeyRecord): string { if (item.isFeedItem || !item.isRegularItem()) return null - log.debug('2797: update', item.id) current = current || blink.first(this.keys, { where: { itemID: item.id } }) @@ -539,7 +537,6 @@ export const KeyManager = new class _KeyManager { if (current && (current.pinned || !this.autopin.enabled) && (current.pinned === proposed.pinned) && (current.citationKey === proposed.citationKey)) return current.citationKey - log.debug('2797: update', item.id, 'to', proposed) if (current) { current.pinned = proposed.pinned current.citationKey = proposed.citationKey