mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix concurrent loadItems in CatalogEntityStore (#4356)
* Fix concurrent loadItems in CatalogEntityStore Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Add parameter to loadItems. Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Remove unnecessary overloading. Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
parent
0587301cc9
commit
14ab00d017
@ -97,12 +97,22 @@ export abstract class ItemStore<Item extends ItemObject> {
|
||||
}
|
||||
|
||||
protected async loadItems(...args: any[]): Promise<any>;
|
||||
/**
|
||||
* Load items to this.items
|
||||
* @param request Function to return the items to be loaded.
|
||||
* @param sortItems If true, items will be sorted.
|
||||
* @param concurrency If true, concurrent loadItems() calls will all be executed. If false, only the first.
|
||||
* @returns
|
||||
*/
|
||||
@action
|
||||
protected async loadItems(request: () => Promise<Item[] | any>, sortItems = true) {
|
||||
protected async loadItems(request: () => Promise<Item[] | any>, sortItems = true, concurrency = false) {
|
||||
if (this.isLoading) {
|
||||
await when(() => !this.isLoading);
|
||||
|
||||
return;
|
||||
// If concurrency for loading is disabled, return instead of loading
|
||||
if (!concurrency) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.isLoading = true;
|
||||
|
||||
|
||||
@ -171,7 +171,7 @@ export class CatalogEntityRegistry {
|
||||
* @param fn The function that should return a truthy value if that entity should be sent currently "active"
|
||||
* @returns A function to remove that filter
|
||||
*/
|
||||
addCatalogFilter(fn: EntityFilter): Disposer {
|
||||
@action addCatalogFilter(fn: EntityFilter): Disposer {
|
||||
this.filters.add(fn);
|
||||
|
||||
return once(() => void this.filters.delete(fn));
|
||||
@ -182,9 +182,7 @@ export class CatalogEntityRegistry {
|
||||
* @param onBeforeRun The function that should return a boolean if the onRun of catalog entity should be triggered.
|
||||
* @returns A function to remove that hook
|
||||
*/
|
||||
addOnBeforeRun(onBeforeRun: CatalogEntityOnBeforeRun): Disposer {
|
||||
logger.debug(`[CATALOG-ENTITY-REGISTRY]: adding onBeforeRun hook`);
|
||||
|
||||
@action addOnBeforeRun(onBeforeRun: CatalogEntityOnBeforeRun): Disposer {
|
||||
this.onBeforeRunHooks.add(onBeforeRun);
|
||||
|
||||
return once(() => void this.onBeforeRunHooks.delete(onBeforeRun));
|
||||
|
||||
@ -65,6 +65,7 @@ export class CatalogEntityStore extends ItemStore<CatalogEntityItem<CatalogEntit
|
||||
}
|
||||
}
|
||||
|
||||
return this.loadItems(() => this.entities);
|
||||
// concurrency is true to fix bug if catalog filter is removed and added at the same time
|
||||
return this.loadItems(() => this.entities, undefined, true);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user