Skip to content

Commit

Permalink
CmdSplit: Do not load entire database
Browse files Browse the repository at this point in the history
Related to issue #245
  • Loading branch information
sruffell committed Jan 6, 2020
1 parent 8f48599 commit 45cf400
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/commands/CmdSplit.cpp
Expand Up @@ -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 ();

std::vector <Interval> intervals = getIntervalsByIds (database, rules, ids);

// Apply tags to ids.
for (auto& id : ids)
for (const auto& interval : intervals)
{
if (id > static_cast <int> (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 ())
Expand All @@ -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 ();
Expand Down

0 comments on commit 45cf400

Please sign in to comment.