-
Notifications
You must be signed in to change notification settings - Fork 55
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
NodeFSStorageAdapter: refactor #215
Conversation
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
}) | ||
) | ||
|
||
return result | ||
} | ||
|
||
async removeRange(keyPrefix: string[]): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should refuse to run this without a key value; pretty sure someone accidentally passing in undefined / empty array would delete everything they have
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok - that should be a separate PR
Okay! Some description would be nice for this one. |
export class NodeFSStorageAdapter extends StorageAdapter { | ||
private baseDirectory: string | ||
private cache: { | ||
[key: string]: { storageKey: StorageKey; data: Uint8Array } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no reason to store the storageKey
in the cache as both a value and a key.
} else { | ||
throw error | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic has been moved to walkdir
|
||
// The "keys" in the cache don't include the baseDirectory. | ||
// We want to de-dupe with the cached keys so we'll use getKey to normalize them. | ||
const diskKeys: string[] = diskFiles | ||
.flat(Infinity) // the walk function returns a nested array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
walkdir
returns a flattened array
await rimraf(dirPath) | ||
} | ||
|
||
private getKey(key: StorageKey): string { | ||
return path.join(...key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getKey
and cacheKey
do the same thing
No changes in behavior, just some minor refactoring for clarity.