mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-11-27 20:45:15 +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:
@@ -27,6 +27,16 @@ var widget = require("$:/core/modules/widgets/widget.js");
|
||||
var USER_NAME_TITLE = "$:/status/UserName",
|
||||
TIMESTAMP_DISABLE_TITLE = "$:/config/TimestampDisable";
|
||||
|
||||
/*
|
||||
Add available indexers to this wiki
|
||||
*/
|
||||
exports.addIndexersToWiki = function() {
|
||||
var self = this;
|
||||
$tw.utils.each($tw.modules.applyMethods("indexer"),function(Indexer,name) {
|
||||
self.addIndexer(new Indexer(self),name);
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
Get the value of a text reference. Text references can have any of these forms:
|
||||
<tiddlertitle>
|
||||
@@ -478,11 +488,18 @@ exports.getOrphanTitles = function() {
|
||||
Retrieves a list of the tiddler titles that are tagged with a given tag
|
||||
*/
|
||||
exports.getTiddlersWithTag = function(tag) {
|
||||
var self = this;
|
||||
return this.getGlobalCache("taglist-" + tag,function() {
|
||||
var tagmap = self.getTagMap();
|
||||
return self.sortByList(tagmap[tag],tag);
|
||||
});
|
||||
// Try to use the indexer
|
||||
var self = this,
|
||||
tagIndexer = this.getIndexer("TagIndexer"),
|
||||
results = tagIndexer && tagIndexer.lookup(tag);
|
||||
if(!results) {
|
||||
// If not available, perform a manual scan
|
||||
results = this.getGlobalCache("taglist-" + tag,function() {
|
||||
var tagmap = self.getTagMap();
|
||||
return self.sortByList(tagmap[tag],tag);
|
||||
});
|
||||
}
|
||||
return results;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user