From 22b398ac0997eec565711bdf527cae9725b9c216 Mon Sep 17 00:00:00 2001 From: Thim Lohse Date: Fri, 9 Oct 2020 01:00:50 +0200 Subject: [PATCH 1/9] first iteration of cached remote values --- package-lock.json | 20 ++++++++++++++ package.json | 2 ++ src/cache/index.ts | 37 ++++++++++++++++++++++++++ src/commands/helpHandler.ts | 1 + src/commands/pickHandler.ts | 2 +- src/entry/cli.ts | 3 ++- src/helpers/branchListPromptPromise.ts | 4 ++- src/helpers/getBranchList.ts | 27 ++++++++++++++----- src/helpers/pickRemoteBranch.ts | 9 +++++-- src/types/index.d.ts | 2 ++ src/types/index.ts | 1 - 11 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 src/cache/index.ts create mode 100644 src/types/index.d.ts delete mode 100644 src/types/index.ts diff --git a/package-lock.json b/package-lock.json index fc8e084..1586b71 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1110,6 +1110,11 @@ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, + "mirrorkey": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mirrorkey/-/mirrorkey-1.2.0.tgz", + "integrity": "sha1-dcPtdLHslZUCnrEcyvHFHfYC/zw=" + }, "mkdirp": { "version": "0.5.5", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", @@ -1136,6 +1141,21 @@ "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, + "node-cache": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/node-cache/-/node-cache-5.1.2.tgz", + "integrity": "sha512-t1QzWwnk4sjLWaQAS8CHgOJ+RAfmHpxFWmc36IWTiWHQfs0w5JDMBS1b1ZxQteo0vVVuWJvIUKHDkkeK7vIGCg==", + "requires": { + "clone": "2.x" + }, + "dependencies": { + "clone": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", + "integrity": "sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18=" + } + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", diff --git a/package.json b/package.json index 6e62666..76781bc 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,8 @@ "inquirer": "^7.3.3", "inquirer-autocomplete-prompt": "^1.2.0", "minimist": "^1.2.5", + "mirrorkey": "^1.2.0", + "node-cache": "^5.1.2", "ora": "^5.1.0", "ramda": "^0.27.1", "tslib": "^2.0.1" diff --git a/src/cache/index.ts b/src/cache/index.ts new file mode 100644 index 0000000..e637123 --- /dev/null +++ b/src/cache/index.ts @@ -0,0 +1,37 @@ +import NodeCache from 'node-cache' +import mirrorKey from 'mirrorkey' +import { } from 'ramda' + +export default class Cache { + private static instance: NodeCache; + private static cacheOptions: NodeCache.Options = { stdTTL: 60 * 5 } + + private constructor() { return } + + /** + * The static method that controls the access to the singleton instance. + * + * This implementation let you subclass the Singleton class while keeping + * just one instance of each subclass around. + */ + public static getInstance(): NodeCache { + if (!Cache.instance) { + Cache.instance = new NodeCache(this.cacheOptions); + } + return Cache.instance; + } + + + public static storeMultiple(array: string[] | undefined): boolean { + if (!array) return false + const multiSet = Object.entries(mirrorKey(array)).map(entry => ({ key: entry[0], val: entry[1] })) + const instance = Cache.getInstance() + return instance.mset(multiSet) + } + + public static getRemoteBranchesFromCache(): string[] { + const instance = Cache.getInstance() + return instance.keys() + + } +} \ No newline at end of file diff --git a/src/commands/helpHandler.ts b/src/commands/helpHandler.ts index 89bc340..c80fddc 100644 --- a/src/commands/helpHandler.ts +++ b/src/commands/helpHandler.ts @@ -23,6 +23,7 @@ const helpDescription: Record = { bl pick