Stop re-fetching the metadata
unconditionally in PDFViewerApplication._initializeJavaScript
We can easily avoid unnecessary API-calls here, since most of the time the `metadata` will already be available here. In the *rare* case that it's not available, we can simply wait for the existing `getMetadata`-call to resolve.
This commit is contained in:
parent
f8ea83609f
commit
bfdb39a1e6
26
web/app.js
26
web/app.js
@ -1417,11 +1417,21 @@ const PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
const calculationOrder = await pdfDocument.getCalculationOrderIds();
|
const calculationOrder = await pdfDocument.getCalculationOrderIds();
|
||||||
const scripting = this.externalServices.scripting;
|
const scripting = this.externalServices.scripting;
|
||||||
const {
|
|
||||||
info,
|
if (!this.documentInfo) {
|
||||||
metadata,
|
// It should be *extremely* rare for metadata to not have been resolved
|
||||||
contentDispositionFilename,
|
// when this code runs, but ensure that we handle that case here.
|
||||||
} = await pdfDocument.getMetadata();
|
await new Promise(resolve => {
|
||||||
|
const metadataLoaded = () => {
|
||||||
|
this.eventBus._off("metadataloaded", metadataLoaded);
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
this.eventBus._on("metadataloaded", metadataLoaded);
|
||||||
|
});
|
||||||
|
if (pdfDocument !== this.pdfDocument) {
|
||||||
|
return; // The document was closed while the metadata resolved.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.addEventListener("updateFromSandbox", event => {
|
window.addEventListener("updateFromSandbox", event => {
|
||||||
const detail = event.detail;
|
const detail = event.detail;
|
||||||
@ -1480,7 +1490,7 @@ const PDFViewerApplication = {
|
|||||||
const dispatchEventName = generateRandomStringForSandbox(objects);
|
const dispatchEventName = generateRandomStringForSandbox(objects);
|
||||||
const { length } = await pdfDocument.getDownloadInfo();
|
const { length } = await pdfDocument.getDownloadInfo();
|
||||||
const filename =
|
const filename =
|
||||||
contentDispositionFilename || getPDFFileNameFromURL(this.url);
|
this.contentDispositionFilename || getPDFFileNameFromURL(this.url);
|
||||||
scripting.createSandbox({
|
scripting.createSandbox({
|
||||||
objects,
|
objects,
|
||||||
dispatchEventName,
|
dispatchEventName,
|
||||||
@ -1490,11 +1500,11 @@ const PDFViewerApplication = {
|
|||||||
language: navigator.language,
|
language: navigator.language,
|
||||||
},
|
},
|
||||||
docInfo: {
|
docInfo: {
|
||||||
...info,
|
...this.documentInfo,
|
||||||
baseURL: this.baseUrl,
|
baseURL: this.baseUrl,
|
||||||
filesize: length,
|
filesize: length,
|
||||||
filename,
|
filename,
|
||||||
metadata,
|
metadata: this.metadata,
|
||||||
numPages: pdfDocument.numPages,
|
numPages: pdfDocument.numPages,
|
||||||
URL: this.url,
|
URL: this.url,
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user