mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-27 05:01:57 +00:00
experimenting with journal/index + notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
6606373142
commit
d06019afaf
@ -263,10 +263,12 @@ module.BaseStore = {
|
|||||||
index = update.call(this, index, name, path, await this.get(path)) }
|
index = update.call(this, index, name, path, await this.get(path)) }
|
||||||
return index } }, {
|
return index } }, {
|
||||||
update: async function(data, name, path, update){
|
update: async function(data, name, path, update){
|
||||||
|
/*/ XXX CACHE_INDEX...
|
||||||
// do not index cache...
|
// do not index cache...
|
||||||
if(this.__cache_path__
|
if(this.__cache_path__
|
||||||
&& path.startsWith(this.__cache_path__)){
|
&& path.startsWith(this.__cache_path__)){
|
||||||
return data }
|
return data }
|
||||||
|
//*/
|
||||||
var {tags, paths} = await data
|
var {tags, paths} = await data
|
||||||
// remove obsolete tags...
|
// remove obsolete tags...
|
||||||
this.__tags.options.remove.call(this, data, name, path)
|
this.__tags.options.remove.call(this, data, name, path)
|
||||||
@ -346,10 +348,12 @@ module.BaseStore = {
|
|||||||
update.call(this, index, name, path, await this.get(path)) }
|
update.call(this, index, name, path, await this.get(path)) }
|
||||||
return index } }, {
|
return index } }, {
|
||||||
update: async function(data, name, path, update){
|
update: async function(data, name, path, update){
|
||||||
|
/*/ XXX CACHE_INDEX...
|
||||||
// do not index cache...
|
// do not index cache...
|
||||||
if(this.__cache_path__
|
if(this.__cache_path__
|
||||||
&& path.startsWith(this.__cache_path__)){
|
&& path.startsWith(this.__cache_path__)){
|
||||||
return data }
|
return data }
|
||||||
|
//*/
|
||||||
var {text, tags} = update
|
var {text, tags} = update
|
||||||
text = [
|
text = [
|
||||||
path,
|
path,
|
||||||
@ -385,7 +389,7 @@ module.BaseStore = {
|
|||||||
changes = changes ?? []
|
changes = changes ?? []
|
||||||
changes.push([Date.now(), action, path, ...args])
|
changes.push([Date.now(), action, path, ...args])
|
||||||
// XXX this needs not to neither trigger handlers nor .index('update', ...)...
|
// XXX this needs not to neither trigger handlers nor .index('update', ...)...
|
||||||
return this.__update(p, {changes}) } },
|
return this.__update(p, {changes}, 'unindexed') } },
|
||||||
save: async function(data, name){
|
save: async function(data, name){
|
||||||
if(this.__cache_path__){
|
if(this.__cache_path__){
|
||||||
var that = this
|
var that = this
|
||||||
@ -431,7 +435,7 @@ module.BaseStore = {
|
|||||||
|
|
||||||
|
|
||||||
// XXX EXPERIMENTAL...
|
// XXX EXPERIMENTAL...
|
||||||
// XXX Q: can we store journal data in a page???
|
// XXX need a persistent fast store of changes...
|
||||||
__journal: index.makeIndex('journal',
|
__journal: index.makeIndex('journal',
|
||||||
function(){
|
function(){
|
||||||
// XXX stub...
|
// XXX stub...
|
||||||
@ -457,31 +461,29 @@ module.BaseStore = {
|
|||||||
this.__journal('clear')
|
this.__journal('clear')
|
||||||
return data },
|
return data },
|
||||||
|
|
||||||
|
// XXX these need to be persistent...
|
||||||
update: function(data, name, path, update){
|
update: function(data, name, path, update){
|
||||||
data.push([Date.now(), 'update', path, update])
|
data.push([Date.now(), 'update', path, update])
|
||||||
return data },
|
return data },
|
||||||
remove: function(data, name, path){
|
remove: function(data, name, path){
|
||||||
data.push([Date.now(), 'remove', path])
|
data.push([Date.now(), 'remove', path])
|
||||||
return data },
|
return data },
|
||||||
//reset: function(){
|
|
||||||
//},
|
|
||||||
save: function(data, name){
|
|
||||||
// XXX move this out...
|
|
||||||
//var idb = require('idb-keyval')
|
|
||||||
// XXX
|
|
||||||
data.push([Date.now(), 'save'])
|
|
||||||
return data},
|
|
||||||
load: function(data, name){
|
|
||||||
// XXX move this out...
|
|
||||||
//var idb = require('idb-keyval')
|
|
||||||
// XXX should we clear the journal here???
|
|
||||||
this.__journal('clear')
|
|
||||||
// load...
|
|
||||||
// XXX
|
|
||||||
|
|
||||||
// XXX
|
save: function(data, name){
|
||||||
data.push([Date.now(), 'load'])
|
data.push([Date.now(), 'save'])
|
||||||
return data}, }),
|
if(this.__cache_path__){
|
||||||
|
var path = this.__cache_path__ +'/'+ name+'_index'
|
||||||
|
this.update(path, {index: data}) }
|
||||||
|
return data},
|
||||||
|
load: async function(data, name){
|
||||||
|
// load...
|
||||||
|
if(this.__cache_path__){
|
||||||
|
var path = this.__cache_path__ +'/'+ name+'_index'
|
||||||
|
data = (await this.get(path) ?? {}).index ?? [] }
|
||||||
|
return data },
|
||||||
|
reset: function(){
|
||||||
|
this.__cache_path__
|
||||||
|
&& this.delete(this.__cache_path__ +'/'+ name+'_index') }, }),
|
||||||
journal: function(){
|
journal: function(){
|
||||||
return this.__journal('__call__', ...arguments)},
|
return this.__journal('__call__', ...arguments)},
|
||||||
|
|
||||||
@ -831,7 +833,19 @@ module.BaseStore = {
|
|||||||
// XXX do we copy the data here or modify it????
|
// XXX do we copy the data here or modify it????
|
||||||
__update__: async function(key, data, mode='update'){
|
__update__: async function(key, data, mode='update'){
|
||||||
this.data[key] = data },
|
this.data[key] = data },
|
||||||
|
//
|
||||||
|
// Unindexed update...
|
||||||
|
// .__update(<path>, <data>, 'unindexed')
|
||||||
|
// .__update(<path>, <data>, 'unindexed', <mode>)
|
||||||
|
// -> <data>
|
||||||
|
//
|
||||||
__update: async function(path, data, mode='update'){
|
__update: async function(path, data, mode='update'){
|
||||||
|
// handle unindexed mode...
|
||||||
|
var index = true
|
||||||
|
if(mode == 'unindexed'){
|
||||||
|
index = false
|
||||||
|
mode = arguments[3]
|
||||||
|
?? 'update' }
|
||||||
// read-only...
|
// read-only...
|
||||||
if(this.__update__ == null){
|
if(this.__update__ == null){
|
||||||
return data }
|
return data }
|
||||||
@ -856,7 +870,8 @@ module.BaseStore = {
|
|||||||
data,
|
data,
|
||||||
{mtime: Date.now()})
|
{mtime: Date.now()})
|
||||||
await this.__update__(path, data, mode)
|
await this.__update__(path, data, mode)
|
||||||
this.index('update', path, data, mode)
|
index
|
||||||
|
&& this.index('update', path, data, mode)
|
||||||
return data },
|
return data },
|
||||||
// XXX can we do a blanket .index('update', ...) here??
|
// XXX can we do a blanket .index('update', ...) here??
|
||||||
// ...currently this will mess up caches between .next/.substores
|
// ...currently this will mess up caches between .next/.substores
|
||||||
@ -872,7 +887,7 @@ module.BaseStore = {
|
|||||||
|
|
||||||
__delete__: async function(path){
|
__delete__: async function(path){
|
||||||
delete this.data[path] },
|
delete this.data[path] },
|
||||||
__delete: async function(path){
|
__delete: async function(path, mode='normal'){
|
||||||
// read-only...
|
// read-only...
|
||||||
if(this.__delete__ == null){
|
if(this.__delete__ == null){
|
||||||
return this }
|
return this }
|
||||||
|
|||||||
19
pwiki2.js
19
pwiki2.js
@ -25,16 +25,21 @@
|
|||||||
* -
|
* -
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
* XXX BUG: <store>.tags.tags seems to be broken -- no paths in sets...
|
||||||
|
* XXX FEATURE: would be nice to have a buffered store (mixin)...
|
||||||
|
* - state stored in memory
|
||||||
|
* - get state from memory (sync)
|
||||||
|
* - background updates (async)
|
||||||
|
* - update strategy
|
||||||
|
* - asap
|
||||||
|
* - timer -- save grouped changes
|
||||||
|
* (changed paths + removed paths)
|
||||||
|
* - idle
|
||||||
|
* - ...
|
||||||
|
* - state query -- pending/saved/...
|
||||||
* XXX Q: can we get state and update in one go???
|
* XXX Q: can we get state and update in one go???
|
||||||
* XXX stored index cache: need to define the save/load strategy + stored
|
* XXX stored index cache: need to define the save/load strategy + stored
|
||||||
* cache validation...
|
* cache validation...
|
||||||
* XXX FEATURE: to avoid reinventing the wheel, serialize stuff as pages...
|
|
||||||
* .paths - ???
|
|
||||||
* .names - ???
|
|
||||||
* .tags - DONE
|
|
||||||
* .search() - DONE
|
|
||||||
* XXX index: pass name to all the handlers...
|
|
||||||
* ...this will simplify generic handlers...
|
|
||||||
* XXX macro: macro:count / macro:index vars can be overridden by count/index
|
* XXX macro: macro:count / macro:index vars can be overridden by count/index
|
||||||
* attributes....
|
* attributes....
|
||||||
* ...this needs testing...
|
* ...this needs testing...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user