Skip to content

Commit

Permalink
Merge branch 'master' into gh-2804
Browse files Browse the repository at this point in the history
  • Loading branch information
retorquere committed Mar 9, 2024
2 parents 896d5d4 + d695874 commit aacdfff
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 85 deletions.
8 changes: 4 additions & 4 deletions content/ErrorReport.ts
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion content/better-bibtex.ts
Expand Up @@ -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))
}

Expand Down
55 changes: 15 additions & 40 deletions content/key-manager.ts
Expand Up @@ -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<number> = new Scheduler<number>('autoPinDelay', 1000)

private started = false
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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<number, CitekeyRecord> = new Map
let key: CitekeyRecord
Expand All @@ -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 }))
Expand All @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion content/translators.ts
Expand Up @@ -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[] = []
Expand Down
62 changes: 31 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -167,16 +167,16 @@
"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",
"showdown": "^2.1.0",
"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",
Expand Down
2 changes: 1 addition & 1 deletion 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: '',
Expand Down
2 changes: 1 addition & 1 deletion submodules/babel
2 changes: 1 addition & 1 deletion submodules/biblatex

0 comments on commit aacdfff

Please sign in to comment.