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

store more than largest kube api request amount in the event store (#1605)

* store more than largest kube api request amount in the event store

* not abstract, give default

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2020-12-04 09:48:56 -05:00 committed by GitHub
parent cb954e6575
commit b342ea0bd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 13 deletions

View File

@ -12,6 +12,7 @@ import { apiManager } from "../../api/api-manager";
export class EventStore extends KubeObjectStore<KubeEvent> {
api = eventApi;
limit = 1000;
saveLimit = 50000;
protected bindWatchEventsUpdater() {
return super.bindWatchEventsUpdater(5000);

View File

@ -11,7 +11,8 @@ import { getHostedCluster } from "../common/cluster-store";
@autobind()
export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemStore<T> {
abstract api: KubeApi<T>;
public limit: number;
public readonly limit?: number;
public readonly bufferSize: number = 50000;
constructor() {
super();
@ -19,6 +20,16 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
kubeWatchApi.addListener(this, this.onWatchApiEvent);
}
get query(): IKubeApiQueryParams {
const { limit } = this;
if (!limit) {
return {};
}
return { limit };
}
getStatuses?(items: T[]): Record<string, number>;
getAllByNs(namespace: string | string[], strict = false): T[] {
@ -62,10 +73,7 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
protected async loadItems(allowedNamespaces?: string[]): Promise<T[]> {
if (!this.api.isNamespaced || !allowedNamespaces) {
const { limit } = this;
const query: IKubeApiQueryParams = limit ? { limit } : {};
return this.api.list({}, query);
return this.api.list({}, this.query);
} else {
return Promise
.all(allowedNamespaces.map(namespace => this.api.list({ namespace })))
@ -179,9 +187,9 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
return;
}
// create latest non-observable copy of items to apply updates in one action (==single render)
let items = this.items.toJS();
const items = this.items.toJS();
this.eventsBuffer.clear().forEach(({ type, object }) => {
for (const {type, object} of this.eventsBuffer.clear()) {
const { uid, selfLink } = object.metadata;
const index = items.findIndex(item => item.getId() === uid);
const item = items[index];
@ -204,14 +212,9 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
}
break;
}
});
// slice to max allowed items
if (this.limit && items.length > this.limit) {
items = items.slice(-this.limit);
}
// update items
this.items.replace(this.sortItems(items));
this.items.replace(this.sortItems(items.slice(-this.bufferSize)));
}
}