Skip to content

Commit

Permalink
refactor: introduce cache for members list fetched by ZE
Browse files Browse the repository at this point in the history
Signed-off-by: Aman Prashant <aman.prashant@broadcom.com>
  • Loading branch information
ap891843 committed Jun 7, 2024
1 parent 4a8572c commit 485ec93
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ describe("Tests Copybook download from DNS", () => {
"document-uri",
"DNS.PATH",
);
expect(allMemberMock).toHaveBeenCalledWith("DNS.PATH");
// cache resolves the members
expect(allMemberMock).not.toHaveBeenCalled();
expect(getContentMock).toHaveBeenCalledWith("DNS.PATH(copybook)", {
file: "profile/dsn.path/copybook",
binary: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ describe("Tests Copybook download from USS", () => {
"document-uri",
"/uss/path",
);
expect(allUSSFilemembers).toHaveBeenCalledWith("/uss/path");
// cache resolves the members
expect(allUSSFilemembers).not.toHaveBeenCalled();
expect(getUSSContentsMock).toHaveBeenCalledWith(
"/uss/path/uss_copybook",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
COPYBOOKS_FOLDER,
ZOWE_FOLDER,
} from "../constants";
import { Utils } from "../services/util/Utils";

/**
* Clears the downloaded copybook cache folder ({globalStoragePath}/.zowe/.copybooks).
Expand Down
1 change: 1 addition & 0 deletions clients/cobol-lsp-vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ function registerCommands(
"cobol-lsp.clear.downloaded.copybooks",
() => {
clearCache(context.globalStorageUri);
copyBooksDownloader.clearCache();
},
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ export class CopybookName {
}

export class CopybookDownloadService {

/**
* Clears any cache maintained by downloaders
*/

clearCache() {
this.downloadResolver.clearCache();
}
private downloadResolver: DownloadStrategyResolver;

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,20 @@ export class CopybookDownloaderForDsn extends ZoweExplorerDownloader {
}

private async getAllMembers(profileName: string, dataset: string) {
const id = this.createId(profileName, dataset);

if (this.memberListCache.has(id)) {
return this.memberListCache.get(id)!;
}

const profile = DownloadUtil.loadProfile(profileName, this.explorerAPI);
const response = await this.explorerAPI
.getMvsApi(DownloadUtil.loadProfile(profileName, this.explorerAPI))
.getMvsApi(profile)
.allMembers(dataset);
return response.apiResponse.items.map((el: any) => el.member);
const members = response.apiResponse.items.map((item: any) => item.member);

this.memberListCache.set(id, members);
return members;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,20 @@ export class CopybookDownloaderForUss extends ZoweExplorerDownloader {
}

private async getAllMembers(profileName: string, dataset: string) {
const id = this.createId(profileName, dataset);

if (this.memberListCache.has(id)) {
return this.memberListCache.get(id)!;
}

const profile = DownloadUtil.loadProfile(profileName, this.explorerAPI);
const response = await this.explorerAPI
.getUssApi(DownloadUtil.loadProfile(profileName, this.explorerAPI))
.getUssApi(profile)
.fileList(dataset);
return response.apiResponse.items.map((el: any) => el.name);
const members = response.apiResponse.items.map((el: any) => el.name);

this.memberListCache.set(id, members);
return members;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ export class DownloadStrategyResolver {
return false;
}

/**
* Clears downloaders cache
*/
clearCache() {
this.dsnDownloader?.clearMemberListCache();
this.ussDownloader?.clearMemberListCache();
}

private async downloadFromPaths(
downloader: CopybookDownloaderForDsn | CopybookDownloaderForUss,
copybook: CopybookName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { CopybookURI } from "../CopybookURI";
export abstract class ZoweExplorerDownloader {
public static profileStore: Map<string, "locked-profile" | "valid-profile"> =
new Map();
protected memberListCache: Map<string, string[]> = new Map();

constructor(
private readonly storagePath: string,
Expand Down Expand Up @@ -96,4 +97,15 @@ export abstract class ZoweExplorerDownloader {

return false;
}

protected createId(profileName: string, path: string) {
return `${profileName}-${path}`;
}

/**
* Clears the member cache for the copybook downloader
*/
public clearMemberListCache() {
this.memberListCache.clear();
}
}

0 comments on commit 485ec93

Please sign in to comment.