mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix concurrent loadItems in CatalogEntityStore
Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
parent
105c875c84
commit
e20e7949fb
@ -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"
|
* @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
|
* @returns A function to remove that filter
|
||||||
*/
|
*/
|
||||||
addCatalogFilter(fn: EntityFilter): Disposer {
|
@action addCatalogFilter(fn: EntityFilter): Disposer {
|
||||||
this.filters.add(fn);
|
this.filters.add(fn);
|
||||||
|
|
||||||
return once(() => void this.filters.delete(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.
|
* @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
|
* @returns A function to remove that hook
|
||||||
*/
|
*/
|
||||||
addOnBeforeRun(onBeforeRun: CatalogEntityOnBeforeRun): Disposer {
|
@action addOnBeforeRun(onBeforeRun: CatalogEntityOnBeforeRun): Disposer {
|
||||||
logger.debug(`[CATALOG-ENTITY-REGISTRY]: adding onBeforeRun hook`);
|
|
||||||
|
|
||||||
this.onBeforeRunHooks.add(onBeforeRun);
|
this.onBeforeRunHooks.add(onBeforeRun);
|
||||||
|
|
||||||
return once(() => void this.onBeforeRunHooks.delete(onBeforeRun));
|
return once(() => void this.onBeforeRunHooks.delete(onBeforeRun));
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { computed, makeObservable, observable, reaction } from "mobx";
|
import { when, computed, makeObservable, observable, reaction } from "mobx";
|
||||||
import { catalogEntityRegistry, CatalogEntityRegistry } from "../../api/catalog-entity-registry";
|
import { catalogEntityRegistry, CatalogEntityRegistry } from "../../api/catalog-entity-registry";
|
||||||
import type { CatalogEntity } from "../../api/catalog-entity";
|
import type { CatalogEntity } from "../../api/catalog-entity";
|
||||||
import { ItemStore } from "../../../common/item.store";
|
import { ItemStore } from "../../../common/item.store";
|
||||||
@ -67,4 +67,35 @@ export class CatalogEntityStore extends ItemStore<CatalogEntityItem<CatalogEntit
|
|||||||
|
|
||||||
return this.loadItems(() => this.entities);
|
return this.loadItems(() => this.entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override ItemStore::loadItems, the only difference is that
|
||||||
|
* if isLoading is true, we await for it to be false and then continue
|
||||||
|
* loading.
|
||||||
|
* This avoids a bug where if there were two or more concurrent loadItems() calls,
|
||||||
|
* only the first one would complete.
|
||||||
|
*/
|
||||||
|
protected async loadItems(
|
||||||
|
request: (() => Promise<CatalogEntityItem<CatalogEntity>[] | any>) | (() => CatalogEntityItem<CatalogEntity>[] | any),
|
||||||
|
sortItems = true,
|
||||||
|
) {
|
||||||
|
if (this.isLoading) {
|
||||||
|
await when(() => !this.isLoading);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isLoading = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let items = await request();
|
||||||
|
|
||||||
|
if (sortItems) {
|
||||||
|
items = this.sortItems(items);
|
||||||
|
}
|
||||||
|
this.items.replace(items);
|
||||||
|
|
||||||
|
this.isLoaded = true;
|
||||||
|
} finally {
|
||||||
|
this.isLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user