Skip to content

Commit 8f1deb9

Browse files
committed
fix #7806 -- reuse in flight project configuration to avoid overloading the backend
1 parent 3431a7c commit 8f1deb9

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

src/packages/frontend/client/project.ts

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ export class ProjectClient {
5050

5151
constructor(client: WebappClient) {
5252
this.client = client;
53-
this.ipywidgetsGetBuffer = reuseInFlight(
54-
this.ipywidgetsGetBuffer.bind(this),
55-
);
5653
}
5754

5855
private async call(message: object): Promise<any> {
@@ -380,16 +377,19 @@ export class ProjectClient {
380377
}
381378

382379
// This is async, so do "await smc_webapp.configuration(...project_id...)".
383-
public async configuration(
384-
project_id: string,
385-
aspect: ConfigurationAspect,
386-
no_cache: boolean,
387-
): Promise<Configuration> {
388-
if (!is_valid_uuid_string(project_id)) {
389-
throw Error("project_id must be a valid uuid");
390-
}
391-
return (await this.api(project_id)).configuration(aspect, no_cache);
392-
}
380+
// for reuseInFlight, see https://github.com/sagemathinc/cocalc/issues/7806
381+
public configuration = reuseInFlight(
382+
async (
383+
project_id: string,
384+
aspect: ConfigurationAspect,
385+
no_cache: boolean,
386+
): Promise<Configuration> => {
387+
if (!is_valid_uuid_string(project_id)) {
388+
throw Error("project_id must be a valid uuid");
389+
}
390+
return (await this.api(project_id)).configuration(aspect, no_cache);
391+
},
392+
);
393393

394394
// Remove all upgrades from all projects that this user collaborates on.
395395
public async remove_all_upgrades(projects?: string[]): Promise<void> {
@@ -543,29 +543,30 @@ export class ProjectClient {
543543
return get_usage_info(project_id);
544544
}
545545

546-
// NOTE: we reuseInFlight this in the constructor.
547-
public async ipywidgetsGetBuffer(
548-
project_id: string,
549-
path: string,
550-
model_id: string,
551-
buffer_path: string,
552-
useHttp?: boolean, // ONLY works for home base, NOT compute servers!
553-
): Promise<ArrayBuffer> {
554-
if (useHttp) {
555-
const url = ipywidgetsGetBufferUrl(
556-
project_id,
557-
path,
546+
public ipywidgetsGetBuffer = reuseInFlight(
547+
async (
548+
project_id: string,
549+
path: string,
550+
model_id: string,
551+
buffer_path: string,
552+
useHttp?: boolean, // ONLY works for home base, NOT compute servers!
553+
): Promise<ArrayBuffer> => {
554+
if (useHttp) {
555+
const url = ipywidgetsGetBufferUrl(
556+
project_id,
557+
path,
558+
model_id,
559+
buffer_path,
560+
);
561+
return await (await fetch(url)).arrayBuffer();
562+
}
563+
const actions = redux.getEditorActions(project_id, path);
564+
return await actions.jupyter_actions.ipywidgetsGetBuffer(
558565
model_id,
559566
buffer_path,
560567
);
561-
return await (await fetch(url)).arrayBuffer();
562-
}
563-
const actions = redux.getEditorActions(project_id, path);
564-
return await actions.jupyter_actions.ipywidgetsGetBuffer(
565-
model_id,
566-
buffer_path,
567-
);
568-
}
568+
},
569+
);
569570

570571
// getting, setting, editing, deleting, etc., the api keys for a project
571572
public async api_keys(opts: {

src/packages/util/smc-version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/* autogenerated by the update_version script */
2-
exports.version=1724777878;
2+
exports.version=1725116922;

0 commit comments

Comments
 (0)