Do not delete and then re-add the latest interval when flattening Database

Eliminates extra noise in the debug output. I.e. from #422 the original
report contained:

  >> 2021-05.data: Deleted inc 20210511T161243Z # "TRACKER-6145"
  >> 2021-05.data: Added inc 20210511T161243Z # "TRACKER-6145"

Which isn't doing anything.

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
This commit is contained in:
Shaun Ruffell 2021-05-13 08:28:10 -05:00 committed by Thomas Lauf
parent bba56cc633
commit 73970b3755

View file

@ -127,6 +127,7 @@ std::vector <Range> getAllExclusions (
}
////////////////////////////////////////////////////////////////////////////////
// Convert what would be synthetic intervals into real intervals in the database
void flattenDatabase (Database& database, const Rules& rules)
{
auto latest = getLatestInterval (database);
@ -135,13 +136,23 @@ void flattenDatabase (Database& database, const Rules& rules)
auto exclusions = getAllExclusions (rules, {latest.start, Datetime ()});
if (! exclusions.empty ())
{
Interval modified {latest};
std::vector <Interval> flattened = flatten (latest, exclusions);
// Update database.
database.deleteInterval (latest);
for (auto& interval : flatten (modified, exclusions))
// If flattened returns only the latest then there are not any synthetic
// intervals to convert.
if (flattened.size () > 1)
{
database.addInterval (interval, rules.getBoolean ("verbose"));
// Update database.
bool verbose = rules.getBoolean ("verbose");
database.deleteInterval (latest);
for (auto& interval : flattened)
{
database.addInterval (interval, verbose);
}
}
else
{
assert (latest == flattened[0]);
}
}
}