1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 23:03:15 +00:00
TiddlyWiki5/core/modules/filters/sameday.js
Jermolene 9fc2086b71 Optimise sameday filter
I used this test:

console.time();for(var t=0; t<200; t++)
{$tw.wiki.filterTiddlers("[all[tiddlers+shadows]sameday[20170210]]");};c
onsole.timeEnd()

Before this patch, I got speeds of approx 190ms, versus 140ms
afterwards.

Note that the ability to add a cache property like this is only
possible because tiddler objects are immutable.
2017-02-21 08:31:05 +00:00

34 lines
763 B
JavaScript

/*\
title: $:/core/modules/filters/sameday.js
type: application/javascript
module-type: filteroperator
Filter operator that selects tiddlers with a modified date field on the same day as the provided value.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.sameday = function(source,operator,options) {
var results = [],
fieldName = operator.suffix || "modified",
targetDate = (new Date($tw.utils.parseDate(operator.operand))).setHours(0,0,0,0);
// Function to convert a date/time to a date integer
source(function(tiddler,title) {
if(tiddler) {
if(tiddler.getFieldDay(fieldName) === targetDate) {
results.push(title);
}
}
});
return results;
};
})();