mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
findListingsOfTiddler should cache results (#6327)
* findListingsOfTiddler uses FieldIndexer now * Turns out FieldIndexer can't help listed[]
This commit is contained in:
parent
af87727ffc
commit
a4ab42da8a
@ -639,14 +639,25 @@ Lookup a given tiddler and return a list of all the tiddlers that include it in
|
||||
*/
|
||||
exports.findListingsOfTiddler = function(targetTitle,fieldName) {
|
||||
fieldName = fieldName || "list";
|
||||
var titles = [];
|
||||
this.each(function(tiddler,title) {
|
||||
var list = $tw.utils.parseStringArray(tiddler.fields[fieldName]);
|
||||
if(list && list.indexOf(targetTitle) !== -1) {
|
||||
titles.push(title);
|
||||
}
|
||||
var wiki = this;
|
||||
var listings = this.getGlobalCache("listings-" + fieldName,function() {
|
||||
var listings = Object.create(null);
|
||||
wiki.each(function(tiddler,title) {
|
||||
var list = $tw.utils.parseStringArray(tiddler.fields[fieldName]);
|
||||
if(list) {
|
||||
for(var i = 0; i < list.length; i++) {
|
||||
var listItem = list[i],
|
||||
listing = listings[listItem] || [];
|
||||
if (listing.indexOf(title) === -1) {
|
||||
listing.push(title);
|
||||
}
|
||||
listings[listItem] = listing;
|
||||
}
|
||||
}
|
||||
});
|
||||
return listings;
|
||||
});
|
||||
return titles;
|
||||
return listings[targetTitle] || [];
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -395,6 +395,11 @@ Tests the filtering mechanism.
|
||||
expect(wiki.filterTiddlers("[list[TiddlerSeventh]sort[title]]").join(",")).toBe("a fourth tiddler,MissingTiddler,Tiddler Three,TiddlerOne");
|
||||
expect(wiki.filterTiddlers("[tag[one]list[TiddlerSeventh]sort[title]]").join(",")).toBe("a fourth tiddler,MissingTiddler,Tiddler Three,TiddlerOne");
|
||||
});
|
||||
|
||||
it("should handle the listed operator", function() {
|
||||
expect(wiki.filterTiddlers("TiddlerOne MissingTiddler +[listed[]]").join(",")).toBe('one,hasList');
|
||||
expect(wiki.filterTiddlers("one two +[listed[tags]]").join(",")).toBe('TiddlerOne,$:/TiddlerTwo,Tiddler Three');
|
||||
});
|
||||
|
||||
it("should handle the next operator", function() {
|
||||
expect(wiki.filterTiddlers("[[Tiddler Three]next[TiddlerSeventh]]").join(",")).toBe("a fourth tiddler");
|
||||
|
Loading…
Reference in New Issue
Block a user