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:
parent
73f9f19cc9
commit
110d2d0e9e
@ -12,6 +12,7 @@ import { apiManager } from "../../api/api-manager";
|
|||||||
export class EventStore extends KubeObjectStore<KubeEvent> {
|
export class EventStore extends KubeObjectStore<KubeEvent> {
|
||||||
api = eventApi;
|
api = eventApi;
|
||||||
limit = 1000;
|
limit = 1000;
|
||||||
|
saveLimit = 50000;
|
||||||
|
|
||||||
protected bindWatchEventsUpdater() {
|
protected bindWatchEventsUpdater() {
|
||||||
return super.bindWatchEventsUpdater(5000);
|
return super.bindWatchEventsUpdater(5000);
|
||||||
|
|||||||
@ -11,7 +11,8 @@ import { getHostedCluster } from "../common/cluster-store";
|
|||||||
@autobind()
|
@autobind()
|
||||||
export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemStore<T> {
|
export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemStore<T> {
|
||||||
abstract api: KubeApi<T>;
|
abstract api: KubeApi<T>;
|
||||||
public limit: number;
|
public readonly limit?: number;
|
||||||
|
public readonly bufferSize: number = 50000;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -19,6 +20,16 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
|
|||||||
kubeWatchApi.addListener(this, this.onWatchApiEvent);
|
kubeWatchApi.addListener(this, this.onWatchApiEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get query(): IKubeApiQueryParams {
|
||||||
|
const { limit } = this;
|
||||||
|
|
||||||
|
if (!limit) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return { limit };
|
||||||
|
}
|
||||||
|
|
||||||
getStatuses?(items: T[]): Record<string, number>;
|
getStatuses?(items: T[]): Record<string, number>;
|
||||||
|
|
||||||
getAllByNs(namespace: string | string[], strict = false): T[] {
|
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[]> {
|
protected async loadItems(allowedNamespaces?: string[]): Promise<T[]> {
|
||||||
if (!this.api.isNamespaced || !allowedNamespaces) {
|
if (!this.api.isNamespaced || !allowedNamespaces) {
|
||||||
const { limit } = this;
|
return this.api.list({}, this.query);
|
||||||
const query: IKubeApiQueryParams = limit ? { limit } : {};
|
|
||||||
|
|
||||||
return this.api.list({}, query);
|
|
||||||
} else {
|
} else {
|
||||||
return Promise
|
return Promise
|
||||||
.all(allowedNamespaces.map(namespace => this.api.list({ namespace })))
|
.all(allowedNamespaces.map(namespace => this.api.list({ namespace })))
|
||||||
@ -179,9 +187,9 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// create latest non-observable copy of items to apply updates in one action (==single render)
|
// 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 { uid, selfLink } = object.metadata;
|
||||||
const index = items.findIndex(item => item.getId() === uid);
|
const index = items.findIndex(item => item.getId() === uid);
|
||||||
const item = items[index];
|
const item = items[index];
|
||||||
@ -204,14 +212,9 @@ export abstract class KubeObjectStore<T extends KubeObject = any> extends ItemSt
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// slice to max allowed items
|
|
||||||
if (this.limit && items.length > this.limit) {
|
|
||||||
items = items.slice(-this.limit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update items
|
// update items
|
||||||
this.items.replace(this.sortItems(items));
|
this.items.replace(this.sortItems(items.slice(-this.bufferSize)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user