From 4059b988a964e1576bdf22324fcd77a222988536 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 1 Sep 2022 00:04:13 +0300 Subject: [PATCH] fixed broken cache... Signed-off-by: Alex A. Naanou --- pwiki/page.js | 49 +++++++++++++++++++++++++++++++------------------ pwiki/path.js | 16 ++++++++-------- pwiki2.js | 9 ++++----- 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/pwiki/page.js b/pwiki/page.js index bf818fe..6836ac9 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -122,14 +122,20 @@ object.Constructor('BasePage', { // XXX should this be able to prevent navigation??? onBeforeNavigate: types.event.Event('beforeNavigate'), onNavigate: types.event.Event('navigate', - function(handle, path){ - this.onBeforeNavigate(path) + function(handle, location){ + this.onBeforeNavigate(location) this.referrer = this.location + var {path, args} = pwpath.splitArgs(location) var cur = this.__location = this.resolvePathVars( - pwpath.relative( - this.location, - path)) + // NOTE: this is done instead of simply assigning + // location as-is to normalize the paths and + // arguments... + pwpath.joinArgs( + pwpath.relative( + this.path, + path), + pwpath.obj2args(args))) // trigger handlers... handle() }), @@ -1331,6 +1337,13 @@ function(obj, name, value){ var CachedPage = module.CachedPage = object.Constructor('CachedPage', Page, { + // Sets what to use for cache id... + // + // Can be: + // 'location' (default) + // 'path' + cache_id: 'location', + // NOTE: set this to null/undefined/0 to disable... cache_timeout: '20m', @@ -1343,21 +1356,21 @@ object.Constructor('CachedPage', Page, { ;(this.root ?? this).__cachestore = value }, get cache(){ - this.checkCache(this.path) - return ((this.cachestore ?? {})[this.path] ?? {}).value }, + this.checkCache(this[this.cache_id]) + return ((this.cachestore ?? {})[this[this.cache_id]] ?? {}).value }, // XXX check * paths for matches... set cache(value){ if(this.cachestore === false || this.cache == value){ return } - var path = this.path + var id = this[this.cache_id ?? 'location'] // clear... if(value == null){ - delete (this.cachestore ?? {})[path] + delete (this.cachestore ?? {})[id] // set... } else { - var prev = ((this.cachestore = this.cachestore ?? {})[path] ?? {}).value ?? {} - ;(this.cachestore = this.cachestore ?? {})[path] = { + var prev = ((this.cachestore = this.cachestore ?? {})[id] ?? {}).value ?? {} + ;(this.cachestore = this.cachestore ?? {})[id] = { created: Date.now(), // XXX valid: undefined, @@ -1373,7 +1386,7 @@ object.Constructor('CachedPage', Page, { // i.e. if we match * as a single path item then we might // miss creating a subtree (ex: /tree), while matching // /* to anything will give us lots of false positives... - if(key != path && deps.has(path)){ + if(key != id && deps.has(id)){ delete this.cachestore[key] } } }, checkCache: function(...paths){ @@ -1665,12 +1678,12 @@ module.System = { tree: { text: object.doc` -
- @source(./name) - - 🛈 - × - +
+
@source(./tree)
diff --git a/pwiki/path.js b/pwiki/path.js index 61fdbba..5cc7bec 100755 --- a/pwiki/path.js +++ b/pwiki/path.js @@ -269,7 +269,6 @@ module = { : [name, ...this.ALTERNATIVE_PAGES] }, - // XXX EXPERIMENTAL... // // .splitArgs() // -> @@ -284,8 +283,6 @@ module = { // } // // Syntax: - // /:/:/../action - // XXX or? // ::= : // ::= // | : @@ -304,7 +301,7 @@ module = { path, args: args.reduce(function(res, arg){ var [name, value] = arg.split(/=(.*)/) - res[name] = value ?? true + res[name.trim()] = value ?? true return res }, {}), } }, obj2args: function(args){ @@ -313,12 +310,15 @@ module = { .map(function([key, value]){ return value === true ? key - //: value === false ? - // [] - : key +':'+ (value.toString().replace(/:/g, '\\:')) - }) + : key +'='+ ((value + '').replace(/:/g, '\\:')) }) .join(':') : args }, + joinArgs: function(path, args={}){ + path = this.join(path) + args = this.obj2args(args) + return args == '' ? + path + : path +':'+ args }, } diff --git a/pwiki2.js b/pwiki2.js index 953905b..d35e7cc 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -1,17 +1,13 @@ /********************************************************************** * * +* XXX ASAP prevent paths from using reserved chars like: ":", "#", ... * XXX FEATURE list macro paging... * ...should this be macro level or handled in .each() * what mode? * - count + block-offset (preferred) * - count + elem-offset * - from + to -* XXX what should page caching use? -* - .path (current) -* - .location -* - .path + normalized .args -* ...should this be configurable??? * XXX FEATURE tags and accompanying API... * - add tags to page -- macro/filter * .text -> .tags (cached on .update(..)) @@ -157,6 +153,9 @@ * - get -- * - download -- * - upload -- +* - tags +* - get tags from page -- +* - show tagged pages -- * - search * - paths * - text