From 9fe46971e6b0e391cb5d876112b1263b797ee1e6 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 24 Aug 2018 13:47:51 +0200 Subject: [PATCH] Flatten db-diskdown directory levels --- packages/db-diskdown/src/index.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/db-diskdown/src/index.ts b/packages/db-diskdown/src/index.ts index fffb67eee..8f058d233 100644 --- a/packages/db-diskdown/src/index.ts +++ b/packages/db-diskdown/src/index.ts @@ -20,6 +20,7 @@ type FilePath = { }; const LRU_SIZE = 8192; +const DIR_DEPTH = 1; const l = logger('db-diskdown'); const noop = () => @@ -47,10 +48,10 @@ class DiskDown extends AbstractLevelDOWN { // NOTE We want to limit the number of entries in any specific directory. Split the // key into parts and use this to construct the path and the actual filename. We want // to limit the entries per directory, but at the same time minimize the number of - // directories we need to create (when non-existent) - const parts = this.__keyToString(key).match(/.{1,2}/g) || []; - const directoryPath = `${this.location}/${parts.slice(0, 3).join('/')}`; - const filePath = `${directoryPath}/${parts.slice(3).join('')}`; + // directories we need to create (when non-existent as well as the size overhead) + const parts = this.__keyToString(key).match(/.{1,3}/g) || []; + const directoryPath = `${this.location}/${parts.slice(0, DIR_DEPTH).join('/')}`; + const filePath = `${directoryPath}/${parts.slice(DIR_DEPTH).join('')}`; let directoryExists = false; let fileExists = true;