diff --git a/pwiki/page.js b/pwiki/page.js index 3933d9f..16be7ae 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -1059,7 +1059,7 @@ object.Constructor('Page', BasePage, { [text, join] = state.macros[name] } } if(src){ - src = await base.parse(src, state) + var base = this.get(await base.parse(src, state)) join = _getBlock('join') ?? join @@ -1070,11 +1070,11 @@ object.Constructor('Page', BasePage, { // of the iterated pages, that is handled by the // respective include/source/.. macros, this however // only depends on page count... - depends.add(src) + depends.add(base.path) // expand matches... var first = true - for await(var page of this.get(src).asPages(strict)){ + for await(var page of base.asPages(strict)){ if(join && !first){ yield join } first = false @@ -1273,27 +1273,38 @@ object.Constructor('CachedPage', Page, { get cache(){ this.checkCache(this.path) return ((this.cachestore ?? {})[this.path] ?? {}).value }, + // XXX check * paths for matches... set cache(value){ if(this.cachestore === false || this.cache == value){ return } var path = this.path + // clear... if(value == null){ delete (this.cachestore ?? {})[path] + // set... } else { + var prev = ((this.cachestore = this.cachestore ?? {})[path] ?? {}).value ?? {} ;(this.cachestore = this.cachestore ?? {})[path] = { created: Date.now(), // XXX valid: undefined, - value, + value: { + ...prev, + ...value, + }, } } // clear depended pages from cache... for(var [key, deps] of Object.entries(this.dependencies)){ + // XXX also check pattern paths... + // ...the problem here is that it's getting probabilistic, + // 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)){ //console.log('CACHE: DROP:', key) delete this.cachestore[key] } } }, - // XXX should this return something useful??? checkCache: function(...paths){ if(!this.cache_timeout || !this.cachestore){ return this } @@ -1311,6 +1322,14 @@ object.Constructor('CachedPage', Page, { //console.log('CACHE: DROP:', this.path) delete this.cachestore[path] } } } return this }, + clearCache: function(...paths){ + if(this.cachestore){ + if(arguments.length == 0){ + this.cachestore = null + } else { + for(var path of paths){ + delete this.cachestore[path] } } } + return this }, __update__: function(){ @@ -1331,11 +1350,12 @@ object.Constructor('CachedPage', Page, { this.path) //*/ - var text = this.cache - ?? object.parentProperty(CachedPage.prototype, 'text').get.call(this) + 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 }) + that.cache = {text} }) return text }, set text(value){ object.parentProperty(CachedPage.prototype, 'text').set.call(this, value) }, @@ -1710,55 +1730,10 @@ module.System = { this.render_root && (this.render_root.location = this.referrer) // show info about the delete operation... - return target.get('DeletingPage').text }, - - /*/ XXX EXPERIMENTAL -- page management... - // move page one level up... - moveUp: function(){ - var target = this.get('..') - var to = '../../'+target.name - - target.move(to) - - // redirect... - this.render_root - && (this.render_root.location = to) - // show info about the move operation... - return this.render_root.path }, - // moves page to current location... - // Example - // /path/to/page/moveDown - // /path/page -> /path/to/page - moveDown: function(){ - var to = this.get('..') - var target = to.get('../../'+ to.name) - - target.move(to.path) - - // redirect... - this.render_root - && (this.render_root.location = to.path) - return this.render_root.path }, - // - // syntax: - // //to:/move - // - // XXX the syntax works, but there are problems with .move(..) method... - move: async function(){ - var [from, to] = this.get('..').path.split(/\/to:/) - // can't move... - if(!from || !to){ - console.warn(`move: can't move: "${from}" -> "${to}"`) - return '' } - - await this.get(from).move(to) - - // redirect... - this.render_root - && (this.render_root.location = to) - return '' }, - //*/ + return target.get('DeletingPage/_text').text }, + // XXX copy/move/... + // ...need arguments // XXX System/back // XXX System/forward diff --git a/pwiki/path.js b/pwiki/path.js index c77bd00..b667741 100755 --- a/pwiki/path.js +++ b/pwiki/path.js @@ -235,7 +235,6 @@ module = { // :, // ... // } - // action: // } // // Syntax: @@ -246,37 +245,22 @@ module = { // | : // ::= // - // | : + // | = // // XXX the problem here is that we could legitimately create path // items containing ":" -- it either needs to be a reserved char // or this scheme will not work... splitArgs: function(path){ - path = this.normalize(path, 'array') + path = this.normalize(path, 'string') + var [path, ...args] = path.split(/:/g) - var res = { - path: '', - args: {}, - actions: path.pop(), - } - var state = 'path' - var cur, value - for(var elem of path){ - if(elem.includes(':')){ - state = 'arg' } - - if(state == 'path'){ - res.path += '/'+ elem - - } else if(state == 'arg'){ - ;[cur, value] = elem.split(':') - res[cur] = value - state = value - - } else if(state == 'value'){ - res[cur] += '/'+ value } } - - return res }, + return { + path, + args: args.reduce(function(res, arg){ + var [name, value] = arg.split('=') + res[name] = value ?? true + return res }, {}), + } }, } diff --git a/pwiki2.js b/pwiki2.js index b1260a6..4a9f608 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -2,6 +2,9 @@ * * * XXX CACHE track store changes... +* XXX CACHE/DEPENDS might be a good idea to add a dependencyUpdated event... +* ...and use it for cache invalidation... +* XXX CACHE creating a new page does not invalidate /tree cache... * XXX need a uniform way to track some state in links in pwiki for things * like paging and the like with simple user/macro access (???)... * ...the simplest that comes to mind is to store in in path @@ -61,6 +64,7 @@ * XXX BUG: .move(..) behaves in an odd way... * see: System/move page action * ...deletes the original and moves an empty page -- sync error??? +* XXX DELETE ./delete is triggered twice... * XXX differences in behaviour between _abc and abc, either need to make * them the same or document the differences and the reasons behind * them...