1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-11-14 14:27:16 +00:00

Add indexes to the wiki store to improve performance (#3951)

* First pass at modular wiki indexes

An exploratory experiment

* Fix tests

* Faster checking for existence of index methods

We don't really need to check the type

* Use the index for the has operator

* Fix typo

* Move iterator index methods into indexer modules

Now boot.js doesn't know the core indexers

* Fix up the other iterator index functions

* Fix crash with missing index branch

* Limit the field indexer to values less than 128 characters

* Fallback to the old manual scan if the index method returns null
* Sadly, we can no longe re-use the field indexer to accelerate the `has` operator, because the index now omits tiddlers that have field values longer than the limit

Still need to make the index configuration exposed somehow

* Rearrange tests so that we can test with and without indexers

We also need to expose the list of enabled indexers as a config option

* Test the field indexer with different length fields

So that we test the indexed and non-indexed codepaths
This commit is contained in:
Jeremy Ruston
2019-05-24 21:07:37 +01:00
committed by GitHub
parent b992b79adb
commit a8f70b08a8
10 changed files with 403 additions and 27 deletions

View File

@@ -1035,7 +1035,23 @@ $tw.Wiki = function(options) {
shadowTiddlerTitles = Object.keys(shadowTiddlers);
}
return shadowTiddlerTitles;
};
},
enableIndexers = options.enableIndexers || null, // Array of indexer names to enable, or null to use all available indexers
indexers = [],
indexersByName = Object.create(null);
this.addIndexer = function(indexer,name) {
// Bail if this indexer is not enabled
if(enableIndexers && enableIndexers.indexOf(name) === -1) {
return;
}
indexers.push(indexer);
indexersByName[name] = indexer;
};
this.getIndexer = function(name) {
return indexersByName[name] || null;
};
// Add a tiddler to the store
this.addTiddler = function(tiddler) {
@@ -1046,6 +1062,7 @@ $tw.Wiki = function(options) {
if(tiddler) {
var title = tiddler.fields.title;
if(title) {
var oldTiddler = this.getTiddler(title);
// Uncomment the following line for detailed logs of all tiddler writes
// console.log("Adding",title,tiddler)
tiddlers[title] = tiddler;
@@ -1054,6 +1071,9 @@ $tw.Wiki = function(options) {
}
this.clearCache(title);
this.clearGlobalCache();
$tw.utils.each(indexers,function(indexer) {
indexer.update(oldTiddler,tiddler);
});
this.enqueueTiddlerEvent(title);
}
}
@@ -1064,6 +1084,7 @@ $tw.Wiki = function(options) {
// Uncomment the following line for detailed logs of all tiddler deletions
// console.log("Deleting",title)
if($tw.utils.hop(tiddlers,title)) {
var oldTiddler = this.getTiddler(title);
delete tiddlers[title];
if(tiddlerTitles) {
var index = tiddlerTitles.indexOf(title);
@@ -1073,6 +1094,10 @@ $tw.Wiki = function(options) {
}
this.clearCache(title);
this.clearGlobalCache();
var newTiddler = this.getTiddler(title);
$tw.utils.each(indexers,function(indexer) {
indexer.update(oldTiddler,newTiddler);
});
this.enqueueTiddlerEvent(title,true);
}
};
@@ -1159,7 +1184,6 @@ $tw.Wiki = function(options) {
callback(tiddlers[title],title);
}
}
};
// Test for the existence of a tiddler (excludes shadow tiddlers)
@@ -1273,8 +1297,14 @@ $tw.Wiki = function(options) {
shadowTiddlerTitles = null;
this.clearCache(null);
this.clearGlobalCache();
$tw.utils.each(indexers,function(indexer) {
indexer.rebuild();
});
};
if(this.addIndexersToWiki) {
this.addIndexersToWiki();
}
};
// Dummy methods that will be filled in after boot