intervalSummarize should not load the entire database

intervalSummarize is called at the end of most commands. The cost of parsing
all the lines in the database can be significant as the size of the database
grows.

Related to issue #245.
This commit is contained in:
Shaun Ruffell 2019-12-23 04:20:18 -06:00 committed by lauft
parent 6af1101ea2
commit cf8c35ad55

View file

@ -30,6 +30,7 @@
#include <format.h> #include <format.h>
#include <Datetime.h> #include <Datetime.h>
#include <Duration.h> #include <Duration.h>
#include <IntervalFactory.h>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
@ -85,13 +86,17 @@ std::string intervalSummarize (
// in the most recent set of intervals for the same tags. This is the // in the most recent set of intervals for the same tags. This is the
// acceptable definition of "the current task". // acceptable definition of "the current task".
time_t total_recorded = 0; time_t total_recorded = 0;
auto inclusions = getAllInclusions (database);
std::vector <Interval>::reverse_iterator i; auto i = database.rbegin ();
for (i = inclusions.rbegin (); i != inclusions.rend (); i++) auto end = database.rend ();
if (interval.tags () == i->tags ()) for (; i != end; ++i)
total_recorded += i->total (); {
Interval current = IntervalFactory::fromSerialization (*i);
if (interval.tags () == current.tags ())
total_recorded += current.total ();
else else
break; break;
}
Duration total (total_recorded); Duration total (total_recorded);