refactored ._checkIndex(..)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2021-02-06 05:32:15 +03:00
parent 26650d63fe
commit 6be15ca2ff
4 changed files with 42 additions and 18 deletions

View File

@ -2769,7 +2769,7 @@ function(title, func){
if(inputs instanceof Array if(inputs instanceof Array
&& (inputs.length == 0 && (inputs.length == 0
|| (inputs[0] || []).length == 0)){ || (inputs[0] || []).length == 0)){
return Promise.resolve(inputs) } return Promise.resolve(inputs[0] || []) }
// Define the runner and prepare... // Define the runner and prepare...
// //
@ -2818,7 +2818,11 @@ function(title, func){
.map(function(e){ .map(function(e){
return [e, ...args] }) return [e, ...args] })
: [[items, ...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... // run...
return (inputs instanceof Promise return (inputs instanceof Promise

View File

@ -855,22 +855,23 @@ var FileSystemLoaderActions = actions.Actions({
}], }],
// XXX EXPERIMENTAL... // XXX EXPERIMENTAL...
// XXX add a context wrapper a-la .makeIndex(..)... // XXX add a context wrapper a-la .makeIndex(..)...
_checkIndex: ['File/Check index consistency', // ...might be a good idea to rename this to .checkIndexPaths(..)
// XXX technically this can be a non-session queue, but we'll // and make the .checkIndex(..) a context aggregate actions like
// need to save the check results... // .makeIndex(..)
// XXX update .handlers to maintain .changes via promise... // 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', core.sessionQueueHandler('checkIndex',
function(queue, ...args){ function(queue, ...args){
// no index loaded... // XXX ignore merged index...
if(!this.location.loaded){ //if((this.location.loaded || []).length > 1){
return [] } // throw new Error('.checkIndex(): combined indexes not supported.') }
// merged index... return [this.images.keys(), ...args] },
// XXX can we remove this restriction -- i.e. check each index... function(gid, ...args){
if(this.location.loaded.length > 1){ var image = this.images[gid]
throw new Error('.checkIndex(): combined indexes not supported.') }
// get the data...
return [Object.entries(this.images), ...args] },
function([gid, image], ...args){
var updated = false var updated = false
// image .previews... // image .previews...
var previews = image.preview || {} var previews = image.preview || {}
@ -879,16 +880,35 @@ var FileSystemLoaderActions = actions.Actions({
!fse.existsSync(image.base_path +'/'+ p[1]) !fse.existsSync(image.base_path +'/'+ p[1])
&& (updated = true) && (updated = true)
&& (delete previews[p[0]]) }) && (delete previews[p[0]]) })
// cleanup...
Object.keys(previews).length == 0 Object.keys(previews).length == 0
&& (delete image.preview) && (delete image.preview)
// image .path... // image .path...
!fse.existsSync(image.base_path +'/'+ image.path) !fse.existsSync(image.base_path +'/'+ image.path)
&& (updated = true) && (updated = true)
&& (delete image.path) && (delete image.path)
// XXX check return values...
return updated ? return updated ?
gid 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 should this take a path argument???
// XXX not yet sure about this... // XXX not yet sure about this...

View File

@ -775,7 +775,6 @@ var SharpActions = actions.Actions({
&& img.flipped == null) && img.flipped == null)
// update metadata... // update metadata...
|| (img.metadata || {}).ImageGridMetadata == null) }) || (img.metadata || {}).ImageGridMetadata == null) })
return [ return [
images, images,
...args, ...args,

View File

@ -419,6 +419,7 @@ module.ImagesPrototype = {
iter: function*(){ iter: function*(){
yield* this }, yield* this },
// XXX do we need a .values() / .entries() here too???
keys: function(){ keys: function(){
var keys = Object.keys(this) var keys = Object.keys(this)
var i = keys.lastIndexOf('version') var i = keys.lastIndexOf('version')