From 45cf400f06b8c4365054068abb0f52b74661b3cf Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Sun, 5 Jan 2020 21:22:15 -0600 Subject: [PATCH] CmdSplit: Do not load entire database Related to issue #245 --- src/commands/CmdSplit.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/commands/CmdSplit.cpp b/src/commands/CmdSplit.cpp index 196c238c..cce88d61 100644 --- a/src/commands/CmdSplit.cpp +++ b/src/commands/CmdSplit.cpp @@ -39,25 +39,20 @@ int CmdSplit ( Database& database, Journal& journal) { + const bool verbose = rules.getBoolean ("verbose"); std::set 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 (); + std::vector intervals = getIntervalsByIds (database, rules, ids); + // Apply tags to ids. - for (auto& id : ids) + for (const auto& interval : intervals) { - if (id > static_cast (tracked.size ())) - throw format ("ID '@{1}' does not correspond to any tracking.", id); - - Interval first = tracked[tracked.size () - id]; + 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 ();