1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Optimize StatefulSet workloads status computation

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2023-03-09 10:04:30 -05:00
parent ab519a9264
commit 8460832d0f
3 changed files with 51 additions and 27 deletions

View File

@ -5,38 +5,24 @@
import { getInjectable } from "@ogre-tools/injectable";
import { workloadInjectionToken } from "../workload-injection-token";
import { ResourceNames } from "../../../../utils/rbac";
import namespaceStoreInjectable from "../../../+namespaces/store.injectable";
import statefulsetsStoreInjectable from "../../../+workloads-statefulsets/store.injectable";
import { computed } from "mobx";
import navigateToStatefulsetsInjectable from "../../../../../common/front-end-routing/routes/cluster/workloads/statefulsets/navigate-to-statefulsets.injectable";
import totalCountOfStatefulSetsInSelectedNamespacesInjectable from "../../../+workloads-statefulsets/total-count.injectable";
import totalStatusesForStatefulSetsInSelectedNamespacesInjectable from "../../../+workloads-statefulsets/statuses.injectable";
const statefulsetsWorkloadInjectable = getInjectable({
id: "statefulsets-workload",
instantiate: (di) => {
const navigate = di.inject(navigateToStatefulsetsInjectable);
const namespaceStore = di.inject(namespaceStoreInjectable);
const store = di.inject(statefulsetsStoreInjectable);
return {
resource: {
apiName: "statefulsets",
group: "apps",
},
open: navigate,
amountOfItems: computed(
() => store.getAllByNs(namespaceStore.contextNamespaces).length,
),
status: computed(() =>
store.getStatuses(store.getAllByNs(namespaceStore.contextNamespaces)),
),
title: ResourceNames.statefulsets,
orderNumber: 40,
};
},
instantiate: (di) => ({
resource: {
apiName: "statefulsets",
group: "apps",
},
open: di.inject(navigateToStatefulsetsInjectable),
amountOfItems: di.inject(totalCountOfStatefulSetsInSelectedNamespacesInjectable),
status: di.inject(totalStatusesForStatefulSetsInSelectedNamespacesInjectable),
title: ResourceNames.statefulsets,
orderNumber: 40,
}),
injectionToken: workloadInjectionToken,
});

View File

@ -0,0 +1,20 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx";
import computeStatusCountsForOwnersInjectable from "../../utils/compute-status-counts.injectable";
import statefulSetStoreInjectable from "./store.injectable";
const totalStatusesForStatefulSetsInSelectedNamespacesInjectable = getInjectable({
id: "total-statuses-for-stateful-sets-in-selected-namespaces",
instantiate: (di) => {
const statefulSetStore = di.inject(statefulSetStoreInjectable);
const computeStatusCountsForOwners = di.inject(computeStatusCountsForOwnersInjectable);
return computed(() => computeStatusCountsForOwners(statefulSetStore.contextItems));
},
});
export default totalStatusesForStatefulSetsInSelectedNamespacesInjectable;

View File

@ -0,0 +1,18 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx";
import statefulSetStoreInjectable from "./store.injectable";
const totalCountOfStatefulSetsInSelectedNamespacesInjectable = getInjectable({
id: "total-count-of-stateful-sets-in-selected-namespaces",
instantiate: (di) => {
const statefulSetStore = di.inject(statefulSetStoreInjectable);
return computed(() => statefulSetStore.getTotalCount());
},
});
export default totalCountOfStatefulSetsInSelectedNamespacesInjectable;