diff --git a/src/TDB.cpp b/src/TDB.cpp index 34d20422f..0eab7439e 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -151,8 +151,34 @@ void TDB::unlock () // multiple files. int TDB::load (std::vector & 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 << "# TDB::load optimization short circuit" << std::endl; +#else loadCompleted (tasks, filter); +#endif return tasks.size (); } diff --git a/src/main.h b/src/main.h index 9f496caaa..4ff2f351c 100644 --- a/src/main.h +++ b/src/main.h @@ -25,6 +25,10 @@ // //////////////////////////////////////////////////////////////////////////////// +// TDB Optimization attempts to reduce the amount of I/O. +#define FEATURE_TDB_OPT 1 + + #include #include #include