1
0
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:
Cameron Fischer 2022-02-21 10:07:30 -05:00 committed by GitHub
parent af87727ffc
commit a4ab42da8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 7 deletions

View File

@ -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] || [];
};
/*

View File

@ -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");