- Implemented ::pendingOnly (was named ::shortcut), for detecting filters
  that do not need to access completed.data.
This commit is contained in:
Paul Beckingham 2014-05-02 23:39:03 -04:00
parent fcb039f801
commit 656dcde272
2 changed files with 23 additions and 22 deletions

View file

@ -45,10 +45,12 @@ static bool domSource (const std::string& identifier, Variant& value)
std::string stringValue = context.dom.get (identifier, *contextTask); std::string stringValue = context.dom.get (identifier, *contextTask);
if (stringValue != identifier) if (stringValue != identifier)
{ {
// std::cout << "# domSource " << identifier << " -> " << stringValue << "\n";
value = Variant (stringValue); value = Variant (stringValue);
return true; return true;
} }
// std::cout << "# domSource " << identifier << " -> ?\n";
return false; return false;
} }
@ -168,7 +170,7 @@ void Filter::subset (std::vector <Task>& output)
std::cout << "# filter mismatch ID " << task->id << " UUID " << task->get ("uuid") << "\n"; std::cout << "# filter mismatch ID " << task->id << " UUID " << task->get ("uuid") << "\n";
} }
if (! shortcut ()) if (! pendingOnly ())
{ {
context.timer_filter.stop (); context.timer_filter.stop ();
const std::vector <Task>& completed = context.tdb2.completed.get_tasks (); // TODO Optional const std::vector <Task>& completed = context.tdb2.completed.get_tasks (); // TODO Optional
@ -213,17 +215,17 @@ void Filter::subset (std::vector <Task>& output)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// If the filter contains the restriction "status:pending", as the first filter // If the filter contains the restriction "status:pending", as the first filter
// term, then completed.data does not need to be loaded. // term, then completed.data does not need to be loaded.
bool Filter::shortcut () bool Filter::pendingOnly ()
{ {
/* Tree* tree = context.a3t.tree ();
// Postfix: <status> <"pending"> <=>
// 0 1 2 // If the filter starts with "status:pending", the completed.data does not
if (filter.size () >= 3 && // need to be accessed..
filter[0]._raw == "status" && if (tree->_branches.size () > 0 &&
filter[1]._raw.find ("pending") != std::string::npos && tree->_branches[0]->attribute ("name") == "status" &&
filter[2]._raw == "=") tree->_branches[0]->attribute ("value") == "pending")
{ {
context.debug ("Command::filter skipping completed.data (status:pending only)"); context.debug ("Filter::pendingOnly - skipping completed.data (status:pending first)");
return true; return true;
} }
@ -232,17 +234,17 @@ bool Filter::shortcut ()
int countUUID = 0; int countUUID = 0;
int countOr = 0; int countOr = 0;
int countXor = 0; int countXor = 0;
std::vector <Arg>::const_iterator i;
for (i = filter.begin (); i != filter.end (); ++i)
{
if (i->_category == Arg::cat_op)
{
if (i->_raw == "or") ++countOr;
if (i->_raw == "xor") ++countXor;
std::vector <Tree*>::iterator i;
for (i = tree->_branches.begin (); i != tree->_branches.end (); ++i)
{
if ((*i)->hasTag ("OP"))
{
if ((*i)->attribute ("canonical") == "or") ++countOr;
if ((*i)->attribute ("canonical") == "xor") ++countXor;
} }
else if (i->_category == Arg::cat_id) ++countId; else if ((*i)->hasTag ("ID")) ++countId;
else if (i->_category == Arg::cat_uuid) ++countUUID; else if ((*i)->hasTag ("UUID")) ++countUUID;
} }
if (countOr == 0 && if (countOr == 0 &&
@ -250,10 +252,9 @@ bool Filter::shortcut ()
countUUID == 0 && countUUID == 0 &&
countId > 0) countId > 0)
{ {
context.debug ("Command::filter skipping completed.data (IDs, no OR, no XOR, no UUID)"); context.debug ("Filter::pendingOnly - skipping completed.data (IDs, no OR, no XOR, no UUID)");
return true; return true;
} }
*/
return false; return false;
} }

View file

@ -38,7 +38,7 @@ public:
void subset (const std::vector <Task>&, std::vector <Task>&); void subset (const std::vector <Task>&, std::vector <Task>&);
void subset (std::vector <Task>&); void subset (std::vector <Task>&);
bool shortcut (); bool pendingOnly ();
void safety (); void safety ();
private: private: