Skip to content

Commit

Permalink
Remove the loop to discover transform function if not registered (jup…
Browse files Browse the repository at this point in the history
…yterlab#14990)

* Remove the loop to discover transform function if not registered

* Update packages/settingregistry/src/settingregistry.ts

Co-authored-by: Michał Krassowski <[email protected]>

* Update packages/settingregistry/src/settingregistry.ts

Co-authored-by: Afshin Taylor Darian <[email protected]>

* Syntax

---------

Co-authored-by: Michał Krassowski <[email protected]>
Co-authored-by: Afshin Taylor Darian <[email protected]>
  • Loading branch information
3 people authored Sep 5, 2023
1 parent 71445cc commit 694d380
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions packages/settingregistry/src/settingregistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ const AJV_DEFAULT_OPTIONS: Partial<AjvOptions> = {
strict: false
};

/**
* The default number of milliseconds before a `load()` call to the registry
* will wait before timing out if it requires a transformation that has not been
* registered.
*/
const DEFAULT_TRANSFORM_TIMEOUT = 1000;

/**
* The ASCII record separator character.
*/
Expand Down Expand Up @@ -280,7 +273,6 @@ export class SettingRegistry implements ISettingRegistry {
constructor(options: SettingRegistry.IOptions) {
this.connector = options.connector;
this.validator = options.validator || new DefaultSchemaValidator();
this._timeout = options.timeout || DEFAULT_TRANSFORM_TIMEOUT;

// Plugins with transformation may not be loaded if the transformation function is
// not yet available. To avoid fetching again the associated data when the transformation
Expand Down Expand Up @@ -605,8 +597,8 @@ export class SettingRegistry implements ISettingRegistry {
// Apply a transformation to the plugin if necessary.
await this._load(await this._transform('fetch', plugin));
} catch (errors) {
/* Ignore preload timeout errors silently. */
if (errors[0]?.keyword !== 'timeout') {
/* Ignore silently if no transformers. */
if (errors[0]?.keyword !== 'unset') {
console.warn('Ignored setting registry preload errors.', errors);
}
}
Expand Down Expand Up @@ -653,13 +645,10 @@ export class SettingRegistry implements ISettingRegistry {
*/
private async _transform(
phase: ISettingRegistry.IPlugin.Phase,
plugin: ISettingRegistry.IPlugin,
started = new Date().getTime()
plugin: ISettingRegistry.IPlugin
): Promise<ISettingRegistry.IPlugin> {
const elapsed = new Date().getTime() - started;
const id = plugin.id;
const transformers = this._transformers;
const timeout = this._timeout;

if (!plugin.schema['jupyter.lab.transform']) {
return plugin;
Expand All @@ -678,25 +667,14 @@ export class SettingRegistry implements ISettingRegistry {
} as ISchemaValidator.IError
];
}

return transformed;
}

// If the timeout has not been exceeded, stall and try again in 250ms.
if (elapsed < timeout) {
await new Promise<void>(resolve => {
setTimeout(() => {
resolve();
}, 250);
});
return this._transform(phase, plugin, started);
}

// If the plugin has no transformers, throw an error and bail.
throw [
{
instancePath: '',
keyword: 'timeout',
message: `Transforming ${plugin.id} timed out.`,
keyword: 'unset',
message: `${plugin.id} has no transformers yet.`,
schemaPath: ''
} as ISchemaValidator.IError
];
Expand All @@ -719,7 +697,6 @@ export class SettingRegistry implements ISettingRegistry {

private _pluginChanged = new Signal<this, string>(this);
private _ready = Promise.resolve();
private _timeout: number;
private _transformers: {
[plugin: string]: {
[phase in ISettingRegistry.IPlugin.Phase]: ISettingRegistry.IPlugin.Transform;
Expand Down

0 comments on commit 694d380

Please sign in to comment.