fixed up caching, some refactoring and tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-09-03 10:57:54 +03:00
parent 816dc731c7
commit d1fdb7a6ca
2 changed files with 22 additions and 9 deletions

View File

@ -368,9 +368,6 @@ module.BaseStore = {
if(path.includes('*')
|| path.includes('**')){
path = pwpath.split(path)
// normalize trailing '/'...
path.at(-1) == ''
&& path.pop()
var p = path.slice()
var tail = []
while(!p.at(-1).includes('*')){
@ -631,7 +628,6 @@ module.MetaStore = {
//
substores: undefined,
// XXX do we need to account for trailing '/' here???
substore: function(path){
path = pwpath.normalize(path, 'string')
if(path in (this.substores ?? {})){
@ -656,7 +652,6 @@ module.MetaStore = {
: store },
getstore: function(path){
return (this.substores ?? {})[this.substore(path)] },
// XXX do we need to account for trailing '/' here???
isStore: function(path){
if(!this.substores){
return false }
@ -786,9 +781,10 @@ module.CachedStore = {
return this },
exists: async function(path){
return path in this.cache ?
path
: object.parentCall(CachedStore.exists, this, ...arguments) },
return (path in this.cache ?
path
: false)
|| object.parentCall(CachedStore.exists, this, ...arguments) },
// XXX this sometimes caches promises...
get: async function(path){
return this.cache[path]
@ -796,7 +792,9 @@ module.CachedStore = {
await object.parentCall(CachedStore.get, this, ...arguments)) },
update: async function(path, data){
var that = this
delete this.cache[path]
var res = object.parentCall(CachedStore.update, this, ...arguments)
// re-cache in the background...
res.then(async function(){
that.cache[path] = await that.get(path) })
return res },

View File

@ -26,6 +26,17 @@
<style>
body {
font-size: 1.1em;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.show-on-hover {
opacity: 0;
}
@ -160,6 +171,8 @@ require(['./browser'], function(browser){
: '/'+path
pwiki.location = [path, hash] })
pwiki
.onBeforeNavigate(function(){
saveNow() })
.onNavigate(function(){
// NOTE: we do not need to directly update location.hash here as
// that will push an extra history item...
@ -207,7 +220,9 @@ require(['./browser'], function(browser){
var SAVE_TIMEOUT = 5000
var SAVE_QUEUE = {}
var saveContent = function(path, text){
SAVE_QUEUE[path] = text }
SAVE_QUEUE[path] = text
// clear editor page cache...
pwiki.cache = null }
var saveNow = function(){
var queue = Object.entries(SAVE_QUEUE)
SAVE_QUEUE = {}