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
&& (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

View File

@ -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...

View File

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

View File

@ -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')