From 7fd2dd5a3eb1d1dfad9716cc6c75202558c392e9 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 19 Jul 2023 21:52:28 +0100 Subject: [PATCH] Wire up the tag indexer properly Improves rendering performance by a factor of 4, but we're still 5 times slower than the plain JS store --- .../tiddlywiki/sqlite3store/sql-wiki-store.js | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/plugins/tiddlywiki/sqlite3store/sql-wiki-store.js b/plugins/tiddlywiki/sqlite3store/sql-wiki-store.js index edfdf7087..6938028b4 100644 --- a/plugins/tiddlywiki/sqlite3store/sql-wiki-store.js +++ b/plugins/tiddlywiki/sqlite3store/sql-wiki-store.js @@ -81,8 +81,14 @@ $tw.Wiki = function(options) { self.sqlFunctions.sqlLogTables(); } + var tagIndexer; + this.addIndexer = function(indexer,name) { - return; + switch(indexer.constructor.name) { + case "TagIndexer": + tagIndexer = new TagIndexer(this); + break; + } }; function TagSubIndexer(indexer,iteratorMethod) { @@ -90,6 +96,13 @@ $tw.Wiki = function(options) { this.iteratorMethod = iteratorMethod; } + TagSubIndexer.prototype.addIndexMethod = function() { + var self = this; + this.indexer.wiki[this.iteratorMethod].byTag = function(tag) { + return self.lookup(tag).slice(0); + }; + }; + TagSubIndexer.prototype.lookup = function(tag) { return self.sqlFunctions.sqlGetTiddlersWithTag(tag,this.iteratorMethod); }; @@ -102,10 +115,11 @@ $tw.Wiki = function(options) { new TagSubIndexer(this,"eachTiddlerPlusShadows"), new TagSubIndexer(this,"eachShadowPlusTiddlers") ]; + $tw.utils.each(this.subIndexers,function(subIndexer) { + subIndexer.addIndexMethod(); + }); } - var tagIndexer = new TagIndexer(); - this.getIndexer = function(name) { switch(name) { case "TagIndexer": @@ -327,6 +341,10 @@ $tw.Wiki = function(options) { this.clearCache(null); this.clearGlobalCache(); }; + + if(this.addIndexersToWiki) { + this.addIndexersToWiki(); + } }; })();