From 1aef90ce19c7d1c101e4e80a637f0052f617c12b Mon Sep 17 00:00:00 2001 From: Romain Date: Sun, 7 Jan 2024 11:06:34 +0000 Subject: [PATCH] fix: make stats displayed during indexing more explicit Before this, the "total" value represented files on disk which was confusing in partial and incremental modes --- src/components/index/index.js | 5 ++-- test/components/index/index.spec.js | 41 +++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/components/index/index.js b/src/components/index/index.js index d6e6d65..af108e5 100644 --- a/src/components/index/index.js +++ b/src/components/index/index.js @@ -59,12 +59,13 @@ class Index { // calculate the difference: which files have been added, modified, etc const deltaFiles = delta.calculate(databaseMap, diskMap, options) emitter.emit('stats', { + database: Object.keys(databaseMap).length, + disk: Object.keys(diskMap).length, unchanged: deltaFiles.unchanged.length, added: deltaFiles.added.length, modified: deltaFiles.modified.length, deleted: deltaFiles.deleted.length, - skipped: deltaFiles.skipped.length, - total: Object.keys(diskMap).length + skipped: deltaFiles.skipped.length }) // remove deleted files from the DB diff --git a/test/components/index/index.spec.js b/test/components/index/index.spec.js index 50ebfdd..757fa92 100644 --- a/test/components/index/index.spec.js +++ b/test/components/index/index.spec.js @@ -34,7 +34,15 @@ describe('Index', function () { it('indexes a folder', (done) => { runIndex({}, data => { should(data.result.count).eql(2) - should(data.stats).eql({ unchanged: 0, added: 2, modified: 0, deleted: 0, skipped: 0, total: 2 }) + should(data.stats).eql({ + database: 0, + disk: 2, + unchanged: 0, + added: 2, + modified: 0, + deleted: 0, + skipped: 0 + }) // check all files were indexed const paths = data.emitted.map(e => e.path).sort() should(paths).eql([ @@ -55,7 +63,15 @@ describe('Index', function () { // then do a second run runIndex({}, data => { should(data.result.count).eql(2) - should(data.stats).eql({ unchanged: 2, added: 0, modified: 0, deleted: 0, skipped: 0, total: 2 }) + should(data.stats).eql({ + database: 2, + disk: 2, + unchanged: 2, + added: 0, + modified: 0, + deleted: 0, + skipped: 0 + }) // all files are emitted, but they were not processed again should(data.emitted).has.length(2) should(data.processed).eql(0) @@ -70,7 +86,15 @@ describe('Index', function () { fixtures.deleteTempFile(tmpdir, 'input/newyork/IMG_0002.jpg') runIndex({}, data => { should(data.result.count).eql(1) - should(data.stats).eql({ unchanged: 1, added: 0, modified: 0, deleted: 1, skipped: 0, total: 1 }) + should(data.stats).eql({ + database: 2, + disk: 1, + unchanged: 1, + added: 0, + modified: 0, + deleted: 1, + skipped: 0 + }) // the remaining file was emitted should(data.emitted).has.length(1) should(data.processed).eql(0) @@ -87,8 +111,15 @@ describe('Index', function () { const options = { scanMode: 'partial', include: ['london/**'] } runIndex(options, data => { should(data.result.count).eql(2) - // note: total is 1 because it scanned 1 file on disk - should(data.stats).eql({ unchanged: 1, added: 0, modified: 0, deleted: 0, skipped: 1, total: 1 }) + should(data.stats).eql({ + database: 2, + disk: 1, + unchanged: 1, + added: 0, + modified: 0, + deleted: 0, + skipped: 1 + }) // but it still emitted 2 files should(data.emitted).has.length(2) should(data.processed).eql(0)