From 6be15ca2ff7aa47ccba86434984b71fdb3d6d48e Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 6 Feb 2021 05:32:15 +0300 Subject: [PATCH] refactored ._checkIndex(..)... Signed-off-by: Alex A. Naanou --- Viewer/features/core.js | 8 ++++-- Viewer/features/filesystem.js | 50 ++++++++++++++++++++++++----------- Viewer/features/sharp.js | 1 - Viewer/imagegrid/images.js | 1 + 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/Viewer/features/core.js b/Viewer/features/core.js index f974149c..6f91ef35 100755 --- a/Viewer/features/core.js +++ b/Viewer/features/core.js @@ -2769,7 +2769,7 @@ function(title, func){ if(inputs instanceof Array && (inputs.length == 0 || (inputs[0] || []).length == 0)){ - return Promise.resolve(inputs) } + return Promise.resolve(inputs[0] || []) } // Define the runner and prepare... // @@ -2818,7 +2818,11 @@ function(title, func){ .map(function(e){ return [e, ...args] }) : [[items, ...args]]) - return q.promise() } } + // XXX do we .flat(..) the results??? + //return q.promise() } } + return q.promise() + .then(function(res){ + return res && res.flat() }) } } // run... return (inputs instanceof Promise diff --git a/Viewer/features/filesystem.js b/Viewer/features/filesystem.js index 9bf55962..775b3f99 100755 --- a/Viewer/features/filesystem.js +++ b/Viewer/features/filesystem.js @@ -855,22 +855,23 @@ var FileSystemLoaderActions = actions.Actions({ }], // XXX EXPERIMENTAL... // XXX add a context wrapper a-la .makeIndex(..)... - _checkIndex: ['File/Check index consistency', - // XXX technically this can be a non-session queue, but we'll - // need to save the check results... - // XXX update .handlers to maintain .changes via promise... + // ...might be a good idea to rename this to .checkIndexPaths(..) + // and make the .checkIndex(..) a context aggregate actions like + // .makeIndex(..) + // XXX might be a good idea to also search for previews here... + // XXX technically this can be a non-session queue, but we'll + // need to save the check results... + // XXX update .handlers to maintain .changes via promise... + checkIndexPaths: ['- File/', + core.doc``, core.sessionQueueHandler('checkIndex', function(queue, ...args){ - // no index loaded... - if(!this.location.loaded){ - return [] } - // merged index... - // XXX can we remove this restriction -- i.e. check each index... - if(this.location.loaded.length > 1){ - throw new Error('.checkIndex(): combined indexes not supported.') } - // get the data... - return [Object.entries(this.images), ...args] }, - function([gid, image], ...args){ + // XXX ignore merged index... + //if((this.location.loaded || []).length > 1){ + // throw new Error('.checkIndex(): combined indexes not supported.') } + return [this.images.keys(), ...args] }, + function(gid, ...args){ + var image = this.images[gid] var updated = false // image .previews... var previews = image.preview || {} @@ -879,16 +880,35 @@ var FileSystemLoaderActions = actions.Actions({ !fse.existsSync(image.base_path +'/'+ p[1]) && (updated = true) && (delete previews[p[0]]) }) + // cleanup... Object.keys(previews).length == 0 && (delete image.preview) // image .path... !fse.existsSync(image.base_path +'/'+ image.path) && (updated = true) && (delete image.path) - // XXX check return values... return updated ? gid : [] })], + _checkIndex: ['- File/', + core.doc``, + function(options={}){ + var context = + options.linked === false ? + this + : this.link() + // XXX we could mark all the index test/recovery actions and + // get them here dynamically... + return Promise.all([ + this.checkIndexPaths(), + // XXX more checks??? + ]).then(function(res){ + // XXX either make res format a protocol requirement or + // revise this... + res.flat().length > 0 + && context.saveIndex() + // XXX this is not returned by the action for some reason... + return res }) }], // XXX should this take a path argument??? // XXX not yet sure about this... diff --git a/Viewer/features/sharp.js b/Viewer/features/sharp.js index 2830205f..9215e2a7 100755 --- a/Viewer/features/sharp.js +++ b/Viewer/features/sharp.js @@ -775,7 +775,6 @@ var SharpActions = actions.Actions({ && img.flipped == null) // update metadata... || (img.metadata || {}).ImageGridMetadata == null) }) - return [ images, ...args, diff --git a/Viewer/imagegrid/images.js b/Viewer/imagegrid/images.js index de6550c8..6ae49b65 100755 --- a/Viewer/imagegrid/images.js +++ b/Viewer/imagegrid/images.js @@ -419,6 +419,7 @@ module.ImagesPrototype = { iter: function*(){ yield* this }, + // XXX do we need a .values() / .entries() here too??? keys: function(){ var keys = Object.keys(this) var i = keys.lastIndexOf('version')