CmdSplit: Do not load entire database

Related to issue #245
This commit is contained in:
Shaun Ruffell 2020-01-05 21:22:15 -06:00 committed by lauft
parent a5493787ad
commit 9aac57c518

View file

@ -39,25 +39,20 @@ int CmdSplit (
Database& database,
Journal& journal)
{
const bool verbose = rules.getBoolean ("verbose");
std::set <int> ids = cli.getIds ();
if (ids.empty ())
throw std::string ("IDs must be specified. See 'timew help split'.");
// Load the data.
// Note: There is no filter.
Interval filter;
auto tracked = getTracked (database, rules, filter);
journal.startTransaction ();
// Apply tags to ids.
for (auto& id : ids)
{
if (id > static_cast <int> (tracked.size ()))
throw format ("ID '@{1}' does not correspond to any tracking.", id);
std::vector <Interval> intervals = getIntervalsByIds (database, rules, ids);
Interval first = tracked[tracked.size () - id];
// Apply tags to ids.
for (const auto& interval : intervals)
{
Interval first = interval;
Interval second = first;
if (first.is_open ())
@ -75,16 +70,16 @@ int CmdSplit (
second.start = midpoint;
}
database.deleteInterval (tracked[tracked.size () - id]);
database.deleteInterval (interval);
validate (cli, rules, database, first);
database.addInterval (first, rules.getBoolean ("verbose"));
database.addInterval (first, verbose);
validate (cli, rules, database, second);
database.addInterval (second, rules.getBoolean ("verbose"));
database.addInterval (second, verbose);
if (rules.getBoolean ("verbose"))
std::cout << "Split @" << id << '\n';
if (verbose)
std::cout << "Split @" << interval.id << '\n';
}
journal.endTransaction ();