mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-30 02:20:08 +00:00 
			
		
		
		
	tweaking and bug-fixes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									f6b1d58805
								
							
						
					
					
						commit
						72e60e4125
					
				| @ -67,7 +67,7 @@ var pwpath = require('../path') | |||||||
| // 		-> <data>
 | // 		-> <data>
 | ||||||
| //
 | //
 | ||||||
| // 	Test if cache is valid...
 | // 	Test if cache is valid...
 | ||||||
| // 	.__<name>_test__(<timestamp>)
 | // 	.__<name>_isvalid__(<timestamp>)
 | ||||||
| // 		-> <bool>
 | // 		-> <bool>
 | ||||||
| //
 | //
 | ||||||
| // 	Handle custom action...
 | // 	Handle custom action...
 | ||||||
| @ -110,7 +110,7 @@ var pwpath = require('../path') | |||||||
| //
 | //
 | ||||||
| //
 | //
 | ||||||
| // XXX do we separate internal methods and actions???
 | // XXX do we separate internal methods and actions???
 | ||||||
| // 		i.e. __<name>_merge__(..) / __<name>_test__(..) and the rest...
 | // 		i.e. __<name>_merge__(..) / __<name>_isvalid__(..) and the rest...
 | ||||||
| var makeIndex =  | var makeIndex =  | ||||||
| module.makeIndex = | module.makeIndex = | ||||||
| function(name, generate, options={}){ | function(name, generate, options={}){ | ||||||
| @ -128,20 +128,25 @@ function(name, generate, options={}){ | |||||||
| 		: !!options.attr ? | 		: !!options.attr ? | ||||||
| 			name | 			name | ||||||
| 		: `__${name}_cache` | 		: `__${name}_cache` | ||||||
|  | 	var test = `__${name}_isvalid__` | ||||||
| 	var merge = `__${name}_merge__` | 	var merge = `__${name}_merge__` | ||||||
| 	var test = `__${name}_test__` |  | ||||||
| 	var special = `__${name}__` | 	var special = `__${name}__` | ||||||
| 	var modified = `__${name}_modified` | 	var modified = `__${name}_modified` | ||||||
| 
 | 
 | ||||||
| 	// make local cache...
 | 	// set modified time...
 | ||||||
| 	var _make = function(){ | 	var _stamp = function(that, res){ | ||||||
| 		var res =  | 		res instanceof Promise ? | ||||||
| 			this[special] != null ? | 			res.then(function(){ | ||||||
| 				this[special]() | 				that[modified] = Date.now() }) | ||||||
| 				: (generate  | 			: (that[modified] = Date.now()) | ||||||
| 					&& generate.call(this)) |  | ||||||
| 		this[modified] = Date.now() |  | ||||||
| 		return res } | 		return res } | ||||||
|  | 	// make local cache...
 | ||||||
|  | 	var _make = function(that){ | ||||||
|  | 		return _stamp(that, | ||||||
|  | 			that[special] != null ? | ||||||
|  | 				that[special]() | ||||||
|  | 				: (generate  | ||||||
|  | 					&& generate.call(that))) } | ||||||
| 	// unwrap a promised value into cache...
 | 	// unwrap a promised value into cache...
 | ||||||
| 	var _await = function(obj, val){ | 	var _await = function(obj, val){ | ||||||
| 		if(val instanceof Promise){ | 		if(val instanceof Promise){ | ||||||
| @ -191,13 +196,13 @@ function(name, generate, options={}){ | |||||||
| 						options[action].call(this, cur, ...args) | 						options[action].call(this, cur, ...args) | ||||||
| 					: cur)  | 					: cur)  | ||||||
| 				res !== cur | 				res !== cur | ||||||
| 					&& (this[modified] = Date.now()) | 					&& _stamp(this, res) | ||||||
| 				return res } | 				return res } | ||||||
| 			// action: get/local...
 | 			// action: get/local...
 | ||||||
| 			return _await(this, | 			return _await(this, | ||||||
| 				// NOTE: this is intentionally not cached...
 | 				// NOTE: this is intentionally not cached...
 | ||||||
| 				action == 'local' ? | 				action == 'local' ? | ||||||
| 					_make.call(this) | 					_make(this) | ||||||
| 				// get...
 | 				// get...
 | ||||||
| 				: (this[cache] = | 				: (this[cache] = | ||||||
| 					// cached...
 | 					// cached...
 | ||||||
| @ -205,9 +210,11 @@ function(name, generate, options={}){ | |||||||
| 						this[cache]  | 						this[cache]  | ||||||
| 					// generate + merge...
 | 					// generate + merge...
 | ||||||
| 					: this[merge] != null ? | 					: this[merge] != null ? | ||||||
| 						this[merge](_make.call(this)) | 						// NOTE: need to set the timestamp after the merge...
 | ||||||
|  | 						_stamp(this,  | ||||||
|  | 							this[merge](_make(this))) | ||||||
| 					// generate...
 | 					// generate...
 | ||||||
| 					: _make.call(this)) ) }, | 					: _make(this)) ) }, | ||||||
| 		{ | 		{ | ||||||
| 			index: name, | 			index: name, | ||||||
| 			indexed: true, | 			indexed: true, | ||||||
| @ -472,7 +479,7 @@ module.BaseStore = { | |||||||
| 					&& 'xpaths' in this.next) ? | 					&& 'xpaths' in this.next) ? | ||||||
| 				await this.next.xpaths | 				await this.next.xpaths | ||||||
| 				: []) }, | 				: []) }, | ||||||
| 	__xpaths_test__: function(t){ | 	__xpaths_isvalid__: function(t){ | ||||||
| 		var changed =  | 		var changed =  | ||||||
| 			!!this.__xpaths_next_exists != !!this.next | 			!!this.__xpaths_next_exists != !!this.next | ||||||
| 				|| (!!this.next  | 				|| (!!this.next  | ||||||
| @ -1069,25 +1076,19 @@ module.MetaStore = { | |||||||
| 		return object.parentCall(MetaStore.__xpaths_merge__, this, ...arguments) | 		return object.parentCall(MetaStore.__xpaths_merge__, this, ...arguments) | ||||||
| 			.iter() | 			.iter() | ||||||
| 			.concat(stores) }, | 			.concat(stores) }, | ||||||
| 	// XXX BUG:
 | 	__xpaths_isvalid__: function(t){ | ||||||
| 	// 		(reload)
 | 		if(this.substores){ | ||||||
| 	// 		pwiki.store.xnames
 | 			// match substore list...
 | ||||||
| 	// 		pwiki.store.substores['Stores/memory'].index('update', 'a/b/c/xxx', {})
 | 			var cur = Object.keys(this.substores ?? {}) | ||||||
| 	// 		pwiki.store.xnames	// does not change...
 | 			var prev = this.__xpaths_substores ?? cur ?? [] | ||||||
| 	__xpaths_test__: function(t){ | 			if(prev.length != cur.length | ||||||
| 		if(!this.substores){ | 					|| (new Set([...cur, ...prev])).size != cur.length){ | ||||||
| 			return true } | 				return false } | ||||||
| 		// match substore list...
 | 			// check timestamps...
 | ||||||
| 		var cur = Object.keys(this.substores ?? {}) | 			for(var {__xpaths_modified} of Object.values(this.substores ?? {})){ | ||||||
| 		var prev = this.__xpaths_substores ?? cur ?? [] | 				if(__xpaths_modified > t){ | ||||||
| 		if(prev.length != cur.length | 					return false } } } | ||||||
| 				|| (new Set([...cur, ...prev])).length != cur.length){ | 		return object.parentCall(MetaStore.__xpaths_isvalid__, this, ...arguments) }, | ||||||
| 			return false } |  | ||||||
| 		// check timestamps...
 |  | ||||||
| 		for(var store of Object.values(this.substores ?? {})){ |  | ||||||
| 			if(store.__xpaths_modified > t){ |  | ||||||
| 				return false } } |  | ||||||
| 		return object.parentCall(MetaStore.__xpaths_test__, this, ...arguments) }, |  | ||||||
| 
 | 
 | ||||||
| 	paths: async function(){ | 	paths: async function(){ | ||||||
| 		var that = this | 		var that = this | ||||||
|  | |||||||
							
								
								
									
										10
									
								
								pwiki2.js
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								pwiki2.js
									
									
									
									
									
								
							| @ -17,7 +17,6 @@ | |||||||
| * 		- CLI | * 		- CLI | ||||||
| * | * | ||||||
| * | * | ||||||
| * XXX odd bug: in node .xpaths seems to get invalidated on each call... |  | ||||||
| * XXX INDEX / CACHE: | * XXX INDEX / CACHE: | ||||||
| * 			- centralized | * 			- centralized | ||||||
| * 			- nestable | * 			- nestable | ||||||
| @ -27,15 +26,6 @@ | |||||||
| * 				name, generate, get (extensible), update, delete | * 				name, generate, get (extensible), update, delete | ||||||
| * 			- event-based??? | * 			- event-based??? | ||||||
| * 			- sync??? | * 			- sync??? | ||||||
| * 		API???: |  | ||||||
| *			// create
 |  | ||||||
| * 			<store>.index(<name>, {generate, update, ... }) |  | ||||||
| * 			delete <store>.index.<name> |  | ||||||
| * 			<store>.<name>				- index data (prop) |  | ||||||
| * 			<store>.__<name>__()		- index getter |  | ||||||
| * 			<store>.index.<name>(..)	- update |  | ||||||
| * 			<store>.index.clear() |  | ||||||
| * 			<store>.index.refresh() |  | ||||||
| * XXX BUG: when editing the root page of a substore the page's .cache is  | * XXX BUG: when editing the root page of a substore the page's .cache is  | ||||||
| * 		not reset for some reason... | * 		not reset for some reason... | ||||||
| * 		...the problem is in that .names() cache is not reset when a new | * 		...the problem is in that .names() cache is not reset when a new | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user