From b2ba27d82ff8d043a6f050ae77b399a671b72ade Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 21 Dec 2020 03:41:11 +0300 Subject: [PATCH] reworked metadata caching... Signed-off-by: Alex A. Naanou --- Viewer/features/cli.js | 12 +++++----- Viewer/features/core.js | 21 +++++++++------- Viewer/features/sharp.js | 52 ++++++++++++++++++++++++++-------------- 3 files changed, 53 insertions(+), 32 deletions(-) diff --git a/Viewer/features/cli.js b/Viewer/features/cli.js index 12f6c649..e7c618e8 100755 --- a/Viewer/features/cli.js +++ b/Viewer/features/cli.js @@ -432,12 +432,12 @@ var CLIActions = actions.Actions({ // XXX this is still wrong... _makeIndex: ['- System/', - `chain: - "loadImages: $1" - "saveIndex" - "makePreviews: 'all'" - "sortImages" - "saveIndex"`], + `chain: [ + "loadImages: $1", + "saveIndex", + "makePreviews: 'all'", + "sortImages", + "saveIndex", ]`], // XXX does not work yet... updateIndex: ['- System/Update index', diff --git a/Viewer/features/core.js b/Viewer/features/core.js index 5821e580..b1699d8e 100755 --- a/Viewer/features/core.js +++ b/Viewer/features/core.js @@ -2716,6 +2716,19 @@ function(title, func){ var q var inputs = [items, ...args] + // pre-process args... + arg_handler + && (inputs = arg_handler.call(this, + sync == 'sync' ? + sync + : q, + ...inputs)) + // special-case: empty inputs -- no need to handle anything... + if(inputs instanceof Array + && inputs[0] + && inputs[0].length == 0){ + return Promise.resolve(inputs) } + // Define the runner and prepare... // // sync mode -- run action outside of queue... @@ -2759,14 +2772,6 @@ function(title, func){ : [items, ...args])) return q.promise() } } - // pre-process args... - arg_handler - && (inputs = arg_handler.call(this, - sync == 'sync' ? - sync - : q, - ...inputs)) - // run... return (inputs instanceof Promise || inputs instanceof runner.FinalizableQueue) ? diff --git a/Viewer/features/sharp.js b/Viewer/features/sharp.js index ebb43a79..6326cf6a 100755 --- a/Viewer/features/sharp.js +++ b/Viewer/features/sharp.js @@ -755,23 +755,39 @@ var SharpActions = actions.Actions({ //{quiet: true, pool_size: 2, busy_timeout_scale: 10}, // parse args... function(queue, image, ...args){ + var that = this var force = false if(image === true){ var [force, image, ...args] = arguments } + + // expand images... + var images = image == 'all' ? + this.images.keys() + : image == 'loaded' ? + this.data.getImages('loaded') + : image instanceof Array ? + image + : [this.data.getImage(image || 'current')] + // narrow down the list... + images = force ? + images + : images + .filter(function(gid){ + var img = that.images[gid] + return img + // high priority must be preset... + && ((img.orientation == null + && img.flipped == null) + // update metadata... + || (img.metadata || {}).ImageGridMetadata == null) }) + return [ - ...(force ? [true] : []), - // expand images.. - image == 'all' ? - this.images.keys() - : image == 'loaded' ? - this.data.getImages('loaded') - : (image || 'current'), + images, + force, ...args, ] }, - function(image, logger){ + function(image, force, logger){ var that = this - if(image === true){ - var [force, image, logger] = arguments } // XXX cache the image data??? var gid = this.data.getImage(image) @@ -886,9 +902,14 @@ module.Sharp = core.ImageGridFeatures.Feature({ isApplicable: function(){ return !!sharp }, handlers: [ - //* XXX this needs to be run in the background... + // NOTE: this is about as fast as filtering the images and + // calling only on the ones needing caching... + // ...but this is not a no-op, especially on very large + // indexes... + // XXX this needs to be run in the background... // XXX this is best done in a thread - [['loadImages', + [['loadIndex' + 'loadImages', 'loadNewImages'], 'cacheMetadata: "all"'], //*/ @@ -929,12 +950,7 @@ module.Sharp = core.ImageGridFeatures.Feature({ that.ribbons.updateImage(gid) // create the rest... - that.makePreviews(gid) - }) - } - }) - } - }] + that.makePreviews(gid) }) } }) } }] //*/ ], })