Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve #7889 avoid 3 fetch calls to load a notebook #7895

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/docmanager-extension/package.json
Expand Up @@ -48,6 +48,7 @@
"@lumino/algorithm": "^1.2.3",
"@lumino/coreutils": "^1.4.2",
"@lumino/disposable": "^1.3.4",
"@lumino/polling": "^1.0.3",
"@lumino/widgets": "^1.10.2"
},
"devDependencies": {
Expand Down
14 changes: 6 additions & 8 deletions packages/docmanager-extension/src/index.ts
Expand Up @@ -44,6 +44,8 @@ import { IDisposable } from '@lumino/disposable';

import { Widget } from '@lumino/widgets';

import { Throttler } from '@lumino/polling';

/**
* The command IDs used by the document manager plugin.
*/
Expand Down Expand Up @@ -244,15 +246,11 @@ ${fileTypes}`;

// callback to registry change that ensures not to invoke reload method when there is already a promise that is pending
let reloadSettingsRegistry = () => {
let promisePending = false;
let reloadThrottle = new Throttler(() =>
settingRegistry.reload(pluginId)
);

return async () => {
if (!promisePending) {
promisePending = true;
await settingRegistry.reload(pluginId);
promisePending = false;
}
};
return reloadThrottle.invoke.bind(reloadThrottle);
};

// If the document registry gains or loses a factory or file type,
Expand Down
52 changes: 36 additions & 16 deletions packages/services/src/contents/index.ts
Expand Up @@ -27,6 +27,14 @@ const SERVICE_DRIVE_URL = 'api/contents';
*/
const FILES_URL = 'files';

/**
* The object to reference listCheckpoints promises
* used as a flag to check and return the existing promise if it's pending
*/
let checkpointPromiseQueue: {
[key: string]: Promise<Contents.ICheckpointModel[]>;
} = {};

/**
* A namespace for contents interfaces.
*/
Expand Down Expand Up @@ -1309,22 +1317,34 @@ export class Drive implements Contents.IDrive {
*/
listCheckpoints(localPath: string): Promise<Contents.ICheckpointModel[]> {
let url = this._getUrl(localPath, 'checkpoints');
return ServerConnection.makeRequest(url, {}, this.serverSettings)
.then(response => {
if (response.status !== 200) {
throw new ServerConnection.ResponseError(response);
}
return response.json();
})
.then(data => {
if (!Array.isArray(data)) {
throw new Error('Invalid Checkpoint list');
}
for (let i = 0; i < data.length; i++) {
validate.validateCheckpointModel(data[i]);
}
return data;
});

if (!checkpointPromiseQueue[localPath]) {
checkpointPromiseQueue[localPath] = ServerConnection.makeRequest(
url,
{},
this.serverSettings
)
.then(response => {
if (response.status !== 200) {
throw new ServerConnection.ResponseError(response);
}
return response.json();
})
.then(data => {
if (!Array.isArray(data)) {
throw new Error('Invalid Checkpoint list');
}
for (let i = 0; i < data.length; i++) {
validate.validateCheckpointModel(data[i]);
}
return data;
})
.finally(() => {
delete checkpointPromiseQueue[localPath];
});
}

return checkpointPromiseQueue[localPath];
}

/**
Expand Down