mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-31 02:50:08 +00:00 
			
		
		
		
	code cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									28fa71ff00
								
							
						
					
					
						commit
						e0238715ec
					
				| @ -182,14 +182,12 @@ module.BaseStore = { | |||||||
| 	// NOTE: this is built from .paths so there is no need to define a 
 | 	// NOTE: this is built from .paths so there is no need to define a 
 | ||||||
| 	// 		way to merge...
 | 	// 		way to merge...
 | ||||||
| 	__names: index.makeIndex('names',  | 	__names: index.makeIndex('names',  | ||||||
| 		function(){ | 		async function(){ | ||||||
| 			return this.paths | 			var update = this.__names.options.update | ||||||
| 				.iter() | 			var index = {} | ||||||
| 				.reduce(function(res, path){ | 			for(var path of (await this.paths)){ | ||||||
| 					var n = pwpath.basename(path) | 				index = update.call(this, index, path) } | ||||||
| 					if(!n.includes('*')){ | 			return index }, { | ||||||
| 						(res[n] = res[n] ?? []).push(path) } |  | ||||||
| 					return res }, {}) }, { |  | ||||||
| 		update: async function(data, path){ | 		update: async function(data, path){ | ||||||
| 			data = await data | 			data = await data | ||||||
| 			// XXX normalize???
 | 			// XXX normalize???
 | ||||||
| @ -251,18 +249,11 @@ module.BaseStore = { | |||||||
| 		return this.__paths_isvalid__(t) }, | 		return this.__paths_isvalid__(t) }, | ||||||
| 	__tags: index.makeIndex('tags',  | 	__tags: index.makeIndex('tags',  | ||||||
| 		async function(){ | 		async function(){ | ||||||
| 			var tags = {} | 			var index = {tags: {}, paths: {}} | ||||||
| 			var paths = {} | 			var update = this.__tags.options.update | ||||||
| 			for(var path of (await this.paths)){ | 			for(var path of (await this.paths)){ | ||||||
| 				var t = (await this.get(path)).tags | 				index = update.call(this, index, path, await this.get(path)) } | ||||||
| 				if(!t){ | 			return index }, { | ||||||
| 					continue } |  | ||||||
| 				paths[path] = new Set(t) |  | ||||||
| 				for(var tag of t){ |  | ||||||
| 					;(tags[tag] =  |  | ||||||
| 							tags[tag] ?? new Set([])) |  | ||||||
| 						.add(path) } } |  | ||||||
| 			return {tags, paths} }, { |  | ||||||
| 		update: async function(data, path, update){ | 		update: async function(data, path, update){ | ||||||
| 			if(!('tags' in update)){ | 			if(!('tags' in update)){ | ||||||
| 				return data } | 				return data } | ||||||
| @ -299,19 +290,29 @@ module.BaseStore = { | |||||||
| 
 | 
 | ||||||
| 	// XXX text search index (???)
 | 	// XXX text search index (???)
 | ||||||
| 	// XXX do we index .data.text or .raw or .text
 | 	// XXX do we index .data.text or .raw or .text
 | ||||||
|  | 	// XXX should we have separate indexes for path, text and tags or 
 | ||||||
|  | 	// 		cram the three together?
 | ||||||
|  | 	// XXX need to store this...
 | ||||||
| 	__search: index.makeIndex('search', | 	__search: index.makeIndex('search', | ||||||
| 		async function(){ | 		async function(){ | ||||||
| 			var index = new flexsearch.Index()  | 			var index = new flexsearch.Index()  | ||||||
|  | 			var update = this.__search.options.update | ||||||
| 			for(var path of (await this.paths)){ | 			for(var path of (await this.paths)){ | ||||||
| 				var text = (await this.get(path)).text | 				update.call(this, index, path, await this.get(path)) } | ||||||
| 				text |  | ||||||
| 					&& typeof(text) != 'function' |  | ||||||
| 					&& index.add(path, text) } |  | ||||||
| 			return index }, { | 			return index }, { | ||||||
| 		update: async function(data, path, update){ | 		update: async function(data, path, update){ | ||||||
| 			update.text | 			var {text, tags} = update | ||||||
| 				&& typeof(update.text) != 'function' | 			text = [ | ||||||
| 				&& (await data).add(path, update.text)  | 				path, | ||||||
|  | 				((text  | ||||||
|  | 						&& typeof(text) != 'function') ? | ||||||
|  | 					text | ||||||
|  | 					: ''), | ||||||
|  | 				(tags ? | ||||||
|  | 					'#'+ tags.join(' #') | ||||||
|  | 					: ''), | ||||||
|  | 			].join('\n\n') | ||||||
|  | 			;(await data).add(path, update.text)  | ||||||
| 			return data }, | 			return data }, | ||||||
| 		remove: async function(data, path){ | 		remove: async function(data, path){ | ||||||
| 			;(await data).remove(path)  | 			;(await data).remove(path)  | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user