mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-29 18:10:09 +00:00
fixed up caching, some refactoring and tweaking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
816dc731c7
commit
d1fdb7a6ca
@ -368,9 +368,6 @@ module.BaseStore = {
|
|||||||
if(path.includes('*')
|
if(path.includes('*')
|
||||||
|| path.includes('**')){
|
|| path.includes('**')){
|
||||||
path = pwpath.split(path)
|
path = pwpath.split(path)
|
||||||
// normalize trailing '/'...
|
|
||||||
path.at(-1) == ''
|
|
||||||
&& path.pop()
|
|
||||||
var p = path.slice()
|
var p = path.slice()
|
||||||
var tail = []
|
var tail = []
|
||||||
while(!p.at(-1).includes('*')){
|
while(!p.at(-1).includes('*')){
|
||||||
@ -631,7 +628,6 @@ module.MetaStore = {
|
|||||||
//
|
//
|
||||||
substores: undefined,
|
substores: undefined,
|
||||||
|
|
||||||
// XXX do we need to account for trailing '/' here???
|
|
||||||
substore: function(path){
|
substore: function(path){
|
||||||
path = pwpath.normalize(path, 'string')
|
path = pwpath.normalize(path, 'string')
|
||||||
if(path in (this.substores ?? {})){
|
if(path in (this.substores ?? {})){
|
||||||
@ -656,7 +652,6 @@ module.MetaStore = {
|
|||||||
: store },
|
: store },
|
||||||
getstore: function(path){
|
getstore: function(path){
|
||||||
return (this.substores ?? {})[this.substore(path)] },
|
return (this.substores ?? {})[this.substore(path)] },
|
||||||
// XXX do we need to account for trailing '/' here???
|
|
||||||
isStore: function(path){
|
isStore: function(path){
|
||||||
if(!this.substores){
|
if(!this.substores){
|
||||||
return false }
|
return false }
|
||||||
@ -786,9 +781,10 @@ module.CachedStore = {
|
|||||||
return this },
|
return this },
|
||||||
|
|
||||||
exists: async function(path){
|
exists: async function(path){
|
||||||
return path in this.cache ?
|
return (path in this.cache ?
|
||||||
path
|
path
|
||||||
: object.parentCall(CachedStore.exists, this, ...arguments) },
|
: false)
|
||||||
|
|| object.parentCall(CachedStore.exists, this, ...arguments) },
|
||||||
// XXX this sometimes caches promises...
|
// XXX this sometimes caches promises...
|
||||||
get: async function(path){
|
get: async function(path){
|
||||||
return this.cache[path]
|
return this.cache[path]
|
||||||
@ -796,7 +792,9 @@ module.CachedStore = {
|
|||||||
await object.parentCall(CachedStore.get, this, ...arguments)) },
|
await object.parentCall(CachedStore.get, this, ...arguments)) },
|
||||||
update: async function(path, data){
|
update: async function(path, data){
|
||||||
var that = this
|
var that = this
|
||||||
|
delete this.cache[path]
|
||||||
var res = object.parentCall(CachedStore.update, this, ...arguments)
|
var res = object.parentCall(CachedStore.update, this, ...arguments)
|
||||||
|
// re-cache in the background...
|
||||||
res.then(async function(){
|
res.then(async function(){
|
||||||
that.cache[path] = await that.get(path) })
|
that.cache[path] = await that.get(path) })
|
||||||
return res },
|
return res },
|
||||||
|
|||||||
17
pwiki2.html
17
pwiki2.html
@ -26,6 +26,17 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-size: 1.1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
.show-on-hover {
|
.show-on-hover {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
@ -160,6 +171,8 @@ require(['./browser'], function(browser){
|
|||||||
: '/'+path
|
: '/'+path
|
||||||
pwiki.location = [path, hash] })
|
pwiki.location = [path, hash] })
|
||||||
pwiki
|
pwiki
|
||||||
|
.onBeforeNavigate(function(){
|
||||||
|
saveNow() })
|
||||||
.onNavigate(function(){
|
.onNavigate(function(){
|
||||||
// NOTE: we do not need to directly update location.hash here as
|
// NOTE: we do not need to directly update location.hash here as
|
||||||
// that will push an extra history item...
|
// that will push an extra history item...
|
||||||
@ -207,7 +220,9 @@ require(['./browser'], function(browser){
|
|||||||
var SAVE_TIMEOUT = 5000
|
var SAVE_TIMEOUT = 5000
|
||||||
var SAVE_QUEUE = {}
|
var SAVE_QUEUE = {}
|
||||||
var saveContent = function(path, text){
|
var saveContent = function(path, text){
|
||||||
SAVE_QUEUE[path] = text }
|
SAVE_QUEUE[path] = text
|
||||||
|
// clear editor page cache...
|
||||||
|
pwiki.cache = null }
|
||||||
var saveNow = function(){
|
var saveNow = function(){
|
||||||
var queue = Object.entries(SAVE_QUEUE)
|
var queue = Object.entries(SAVE_QUEUE)
|
||||||
SAVE_QUEUE = {}
|
SAVE_QUEUE = {}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user