mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Optimization
- TDB::load can entirely skip the loading of completed.data if the specified filter is just so. - Added FEATURE_TDB_OPT definition to allow disabling of this.
This commit is contained in:
parent
7a77cd6d4a
commit
e7a0a20d55
2 changed files with 31 additions and 1 deletions
28
src/TDB.cpp
28
src/TDB.cpp
|
@ -151,8 +151,34 @@ void TDB::unlock ()
|
|||
// multiple files.
|
||||
int TDB::load (std::vector <Task>& tasks, Filter& filter)
|
||||
{
|
||||
loadPending (tasks, filter);
|
||||
#ifdef FEATURE_TDB_OPT
|
||||
// Special optimization: if the filter contains Att ('status', '', 'pending'),
|
||||
// and no other 'status' filters, then loadCompleted can be skipped.
|
||||
int numberStatusClauses = 0;
|
||||
int numberSimpleStatusClauses = 0;
|
||||
foreach (att, filter)
|
||||
{
|
||||
if (att->name () == "status")
|
||||
{
|
||||
++numberStatusClauses;
|
||||
|
||||
if (att->mod () == "" && att->value () == "pending")
|
||||
++numberSimpleStatusClauses;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
loadPending (tasks, filter);
|
||||
|
||||
#ifdef FEATURE_TDB_OPT
|
||||
if (numberStatusClauses == 0 ||
|
||||
numberStatusClauses != numberSimpleStatusClauses)
|
||||
loadCompleted (tasks, filter);
|
||||
else
|
||||
std::cout << "[1;31m# TDB::load optimization short circuit[0m" << std::endl;
|
||||
#else
|
||||
loadCompleted (tasks, filter);
|
||||
#endif
|
||||
|
||||
return tasks.size ();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,10 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TDB Optimization attempts to reduce the amount of I/O.
|
||||
#define FEATURE_TDB_OPT 1
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue