Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(inji-411): Remove caching for vc files #995

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions machines/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
isHardwareKeystoreExists,
} from '../shared/cryptoutil/cryptoUtil';
import {VCMetadata} from '../shared/VCMetadata';
import FileStorage, {getFilePath} from '../shared/fileStorage';

export const keyinvalidatedString =
'Key Invalidated due to biometric enrollment';
Expand Down Expand Up @@ -173,7 +172,7 @@ export const storeMachine =
},
},
ready: {
entry: ['notifyParent', 'cacheVCFilesData'],
entry: 'notifyParent',
invoke: {
src: 'store',
id: '_store',
Expand Down Expand Up @@ -259,18 +258,6 @@ export const storeMachine =
setEncryptionKey: model.assign({
encryptionKey: (_, event) => event.key,
}),

cacheVCFilesData: context => {
getItem(MY_VCS_STORE_KEY, [], context.encryptionKey).then(vcList => {
if (vcList) {
vcList?.forEach((vcMetadataStr: string) => {
const vcKey =
VCMetadata.fromVcMetadataString(vcMetadataStr).getVcKey();
FileStorage.readAndCacheFile(getFilePath(vcKey));
});
}
});
},
},

services: {
Expand Down
28 changes: 0 additions & 28 deletions shared/fileStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,6 @@ class FileStorage {
return await readFile(path, 'utf8');
}

async readFromCacheFile(path: string) {
if (this.cache[path]?.data) {
const count = this.cache[path]?.count ?? 0;
const data = this.cache[path]?.data;

if (count != undefined && count <= 1) {
this.cache[path] = {};
} else {
this.cache[path].count = count - 1;
}

return data;
}

return this.readFile(path);
}

async readAndCacheFile(path: string, useCount: number = 1) {
const data = await this.readFile(path);

this.cache[path] = {
data,
count: useCount,
};

return data;
}

async writeFile(path: string, data: string) {
return await writeFile(path, data, 'utf8');
}
Expand Down
2 changes: 1 addition & 1 deletion shared/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Storage {
}

private static async readVCFromFile(key: string) {
return await FileStorage.readFromCacheFile(getFilePath(key));
return await FileStorage.readFile(getFilePath(key));
}

private static async storeVC(key: string, data: string) {
Expand Down