From 773332436befb5a6cbb7328529f0e2db03d0509f Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 24 Aug 2022 23:47:42 +0300 Subject: [PATCH] cleanup and notes... Signed-off-by: Alex A. Naanou --- pwiki/page.js | 42 +++++++++++++++++++++++------------------- pwiki/store/base.js | 2 +- pwiki2.js | 2 -- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/pwiki/page.js b/pwiki/page.js index bab33ec..b84724f 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -1255,6 +1255,18 @@ object.Constructor('Page', BasePage, { //--------------------------------------------------------------------- +var getCachedProp = function(obj, name){ + var that = obj + var value = obj.cache ? + obj.cache[name] + : object.parentProperty(CachedPage.prototype, name).get.call(obj) + value instanceof Promise + && value.then(function(value){ + that.cache = {[name]: value} }) + return value } +var setCachedProp = function(obj, name, value){ + return object.parentProperty(CachedPage.prototype, name).set.call(obj, value) } + // XXX this is good enough on the front-side to think about making the // cache persistent with a very large timeout (if set at all), but // we are not tracking changes on the store-side... @@ -1304,7 +1316,6 @@ object.Constructor('CachedPage', Page, { // miss creating a subtree (ex: /tree), while matching // /* to anything will give us lots of false positives... if(key != path && deps.has(path)){ - //console.log('CACHE: DROP:', key) delete this.cachestore[key] } } }, checkCache: function(...paths){ @@ -1341,26 +1352,19 @@ object.Constructor('CachedPage', Page, { this.cache = null return object.parentCall(CachedPage.prototype.__delete__, this, ...arguments) }, + /* XXX do we need to cache .raw??? + // ...yes this makes things marginally faster but essentially + // copies the db into memory... + get raw(){ + return getCachedProp(this, 'raw') }, + set raw(value){ + return setCachedProp(this, 'raw', value) }, + //*/ + get text(){ - var that = this - - /* XXX - console.log( - this.cache ? - 'CACHED:' - : 'RENDER:', - this.path) - //*/ - - var text = this.cache ? - this.cache.text - : object.parentProperty(CachedPage.prototype, 'text').get.call(this) - text instanceof Promise - && text.then(function(text){ - that.cache = {text} }) - return text }, + return getCachedProp(this, 'text') }, set text(value){ - object.parentProperty(CachedPage.prototype, 'text').set.call(this, value) }, + return setCachedProp(this, 'text', value) }, }) diff --git a/pwiki/store/base.js b/pwiki/store/base.js index 1c25cf0..0e5ed03 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -663,7 +663,7 @@ module.MetaStore = { // XXX TEST... var CachedStore = module.CachedStore = { - //__proto__: FileStoreRO, + __proto__: MetaStore, // format: // { diff --git a/pwiki2.js b/pwiki2.js index 65e372d..fde46cb 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -1,8 +1,6 @@ /********************************************************************** * * -* XXX BUG: -* await pwiki.get('/* /path').text -> '' (wrong) * XXX NORMCACHE .normalize(..) cache normalized strings... * ...seems to have little impact... * XXX MATCH limit candidates to actual page name matches -- this will