Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
* move deletePackageCache to registry/index.ts
* clean up imports
  • Loading branch information
skh committed Sep 8, 2020
1 parent 550356f commit 897ea53
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import { getInstallation, savedObjectTypes } from './index';
import { deletePipeline } from '../elasticsearch/ingest_pipeline/';
import { installIndexPatterns } from '../kibana/index_pattern/install';
import { packagePolicyService, appContextService } from '../..';
import { splitPkgKey } from '../registry';
import { deletePackageCache } from '../registry/cache';
import * as Registry from '../registry';
import { splitPkgKey, deletePackageCache, getArchiveInfo } from '../registry';

export async function removeInstallation(options: {
savedObjectsClient: SavedObjectsClientContract;
Expand Down Expand Up @@ -54,7 +52,7 @@ export async function removeInstallation(options: {

// remove the package archive and its contents from the cache so that a reinstall fetches
// a fresh copy from the registry
const paths = await Registry.getArchiveInfo(pkgName, pkgVersion);
const paths = await getArchiveInfo(pkgName, pkgVersion);
deletePackageCache(pkgName, pkgVersion, paths);

// successful delete's in SO client return {}. return something more useful
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,3 @@ export const setArchiveLocation = (name: string, version: string, location: stri

export const deleteArchiveLocation = (name: string, version: string) =>
archiveLocationCache.delete(pkgToPkgKey({ name, version }));

export const deletePackageCache = (name: string, version: string, paths: string[]) => {
const archiveLocation = getArchiveLocation(name, version);
if (archiveLocation) {
// delete cached archive
cacheDelete(archiveLocation);

// delete cached archive location
deleteArchiveLocation(name, version);
}
// delete cached archive contents
// this has been populated in Registry.getArchiveInfo()
// TODO: move cache population and cache cleanup closer together?
paths.forEach((path) => cacheDelete(path));
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ import {
RegistrySearchResults,
RegistrySearchResult,
} from '../../../types';
import { cacheGet, cacheSet, cacheHas, getArchiveLocation, setArchiveLocation } from './cache';
import {
cacheGet,
cacheSet,
cacheDelete,
cacheHas,
getArchiveLocation,
setArchiveLocation,
deleteArchiveLocation,
} from './cache';
import { ArchiveEntry, untarBuffer, unzipBuffer } from './extract';
import { fetchUrl, getResponse, getResponseStream } from './requests';
import { streamToBuffer } from './streams';
Expand Down Expand Up @@ -241,3 +249,17 @@ export function groupPathsByService(paths: string[]): AssetsGroupedByServiceByTy
// elasticsearch: assets.elasticsearch,
};
}

export const deletePackageCache = (name: string, version: string, paths: string[]) => {
const archiveLocation = getArchiveLocation(name, version);
if (archiveLocation) {
// delete cached archive
cacheDelete(archiveLocation);

// delete cached archive location
deleteArchiveLocation(name, version);
}
// delete cached archive contents
// this has been populated in Registry.getArchiveInfo()
paths.forEach((path) => cacheDelete(path));
};

0 comments on commit 897ea53

Please sign in to comment.