Skip to content

Commit

Permalink
Create Kafka client with lazy mode (only when cluster item is expanded).
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr authored and fbricon committed Mar 10, 2021
1 parent 7a0914c commit bf47c3d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/explorer/models/cluster.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode";

import { Cluster, Client } from "../../client";
import { Cluster, Client, ClientAccessor } from "../../client";
import { NodeBase } from "./nodeBase";
import { BrokerGroupItem } from "./brokers";
import { TopicGroupItem, TopicItem } from "./topics";
Expand All @@ -16,12 +16,16 @@ export class ClusterItem extends NodeBase implements Disposable {
public contextValue = "cluster";
public collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;

constructor(public client: Client, public readonly cluster: Cluster, parent: KafkaModel) {
constructor(private clientAccessor: ClientAccessor, public readonly cluster: Cluster, parent: KafkaModel) {
super(parent);
this.label = cluster.name;
this.description = cluster.bootstrap;
}

public get client(): Client {
return this.clientAccessor.get(this.cluster.id);
}

async computeChildren(): Promise<NodeBase[]> {
return [
new BrokerGroupItem(this),
Expand Down
4 changes: 2 additions & 2 deletions src/explorer/models/kafka.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Disposable, TreeItemCollapsibleState } from "vscode";
import { ClientAccessor } from "../../client";
import { ClusterSettings } from "../../settings";
import { ClusterItem} from "./cluster";
import { ClusterItem } from "./cluster";
import { NodeBase } from "./nodeBase";

export class KafkaModel extends NodeBase implements Disposable {
Expand All @@ -18,7 +18,7 @@ export class KafkaModel extends NodeBase implements Disposable {
public async computeChildren(): Promise<NodeBase[]> {
const clusters = this.clusterSettings.getAll();
return clusters.map((c) => {
return new ClusterItem(this.clientAccessor.get(c.id), c, this);
return new ClusterItem(this.clientAccessor, c, this);
});
}

Expand Down

0 comments on commit bf47c3d

Please sign in to comment.