mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2026-10-05 07:31:43 +00:00
Sort tag lookups according to TW semantics
Perhaps it would be better to keep the tags in the desired order in the database...
This commit is contained in:
@@ -94,6 +94,7 @@ $tw.Wiki = function(options) {
|
|||||||
function TagSubIndexer(indexer,iteratorMethod) {
|
function TagSubIndexer(indexer,iteratorMethod) {
|
||||||
this.indexer = indexer;
|
this.indexer = indexer;
|
||||||
this.iteratorMethod = iteratorMethod;
|
this.iteratorMethod = iteratorMethod;
|
||||||
|
this.cache = Object.create(null); // Hashmap by title containing arrays of titles
|
||||||
}
|
}
|
||||||
|
|
||||||
TagSubIndexer.prototype.addIndexMethod = function() {
|
TagSubIndexer.prototype.addIndexMethod = function() {
|
||||||
@@ -103,8 +104,21 @@ $tw.Wiki = function(options) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TagSubIndexer.prototype.update = function(updateDescriptor) {
|
||||||
|
this.cache = Object.create(null);
|
||||||
|
};
|
||||||
|
|
||||||
TagSubIndexer.prototype.lookup = function(tag) {
|
TagSubIndexer.prototype.lookup = function(tag) {
|
||||||
return self.sqlFunctions.sqlGetTiddlersWithTag(tag,this.iteratorMethod);
|
var cachedResult = this.cache[tag];
|
||||||
|
if(cachedResult) {
|
||||||
|
return cachedResult;
|
||||||
|
}
|
||||||
|
var listing = self.sqlFunctions.sqlGetTiddlersWithTag(tag,this.iteratorMethod);
|
||||||
|
if(this.indexer.wiki.sortByList) {
|
||||||
|
listing = this.indexer.wiki.sortByList(listing,tag);
|
||||||
|
}
|
||||||
|
this.cache[tag] = listing;
|
||||||
|
return listing;
|
||||||
};
|
};
|
||||||
|
|
||||||
function TagIndexer(wiki) {
|
function TagIndexer(wiki) {
|
||||||
@@ -120,6 +134,12 @@ $tw.Wiki = function(options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TagIndexer.prototype.update = function(updateDescriptor) {
|
||||||
|
$tw.utils.each(this.subIndexers,function(subIndexer) {
|
||||||
|
subIndexer.update(updateDescriptor);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
this.getIndexer = function(name) {
|
this.getIndexer = function(name) {
|
||||||
switch(name) {
|
switch(name) {
|
||||||
case "TagIndexer":
|
case "TagIndexer":
|
||||||
@@ -142,6 +162,9 @@ $tw.Wiki = function(options) {
|
|||||||
// Update caches
|
// Update caches
|
||||||
this.clearCache(title);
|
this.clearCache(title);
|
||||||
this.clearGlobalCache();
|
this.clearGlobalCache();
|
||||||
|
if(tagIndexer) {
|
||||||
|
tagIndexer.update();
|
||||||
|
}
|
||||||
// Queue a change event
|
// Queue a change event
|
||||||
this.enqueueTiddlerEvent(title);
|
this.enqueueTiddlerEvent(title);
|
||||||
}
|
}
|
||||||
@@ -158,6 +181,9 @@ $tw.Wiki = function(options) {
|
|||||||
// Update caches
|
// Update caches
|
||||||
this.clearCache(title);
|
this.clearCache(title);
|
||||||
this.clearGlobalCache();
|
this.clearGlobalCache();
|
||||||
|
if(tagIndexer) {
|
||||||
|
tagIndexer.update();
|
||||||
|
}
|
||||||
// Queue a change event
|
// Queue a change event
|
||||||
this.enqueueTiddlerEvent(title,true);
|
this.enqueueTiddlerEvent(title,true);
|
||||||
}
|
}
|
||||||
@@ -340,6 +366,9 @@ $tw.Wiki = function(options) {
|
|||||||
});
|
});
|
||||||
this.clearCache(null);
|
this.clearCache(null);
|
||||||
this.clearGlobalCache();
|
this.clearGlobalCache();
|
||||||
|
if(tagIndexer) {
|
||||||
|
tagIndexer.update();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if(this.addIndexersToWiki) {
|
if(this.addIndexersToWiki) {
|
||||||
|
|||||||
Reference in New Issue
Block a user