Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Replica::pending_tasks #3661

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/TDB2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,12 @@ const std::vector<Task> TDB2::all_tasks() {
const std::vector<Task> TDB2::pending_tasks() {
if (!_pending_tasks) {
Timer timer;
auto& ws = working_set();
auto largest_index = ws->largest_index();

auto pending_tctasks = replica()->pending_task_data();
std::vector<Task> result;
for (size_t i = 0; i <= largest_index; i++) {
auto uuid = ws->by_index(i);
if (!uuid.is_nil()) {
auto maybe_task = replica()->get_task_data(uuid);
if (maybe_task.is_some()) {
result.push_back(Task(maybe_task.take()));
}
}
for (auto& maybe_tctask : pending_tctasks) {
auto tctask = maybe_tctask.take();
result.push_back(Task(std::move(tctask)));
}

dependency_scan(result);
Expand Down
20 changes: 18 additions & 2 deletions src/taskchampion-cpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,16 @@ mod ffi {
fn commit_reversed_operations(&mut self, ops: Vec<Operation>) -> Result<bool>;

/// Get `TaskData` values for all tasks in the replica.

///
/// This contains `OptionTaskData` to allow C++ to `take` values out of the vector and use
/// them as `rust::Box<TaskData>`. Cxx does not support `Vec<Box<_>>`. Cxx also does not
/// handle `HashMap`, so the result is not a map from uuid to task. The returned Vec is
/// fully populated, so it is safe to call `take` on each value in the returned Vec once .
fn all_task_data(&mut self) -> Result<Vec<OptionTaskData>>;

/// Simiar to all_task_data, but returing only pending tasks (those in the working set).
fn pending_task_data(&mut self) -> Result<Vec<OptionTaskData>>;

/// Get the UUIDs of all tasks.
fn all_task_uuids(&mut self) -> Result<Vec<Uuid>>;

Expand Down Expand Up @@ -500,6 +503,15 @@ impl Replica {
.collect())
}

fn pending_task_data(&mut self) -> Result<Vec<ffi::OptionTaskData>, CppError> {
Ok(self
.0
.pending_task_data()?
.drain(..)
.map(|t| Some(t).into())
.collect())
}

fn all_task_uuids(&mut self) -> Result<Vec<ffi::Uuid>, CppError> {
Ok(self
.0
Expand Down Expand Up @@ -870,10 +882,14 @@ mod test {
add_undo_point(&mut operations);
create_task(uuid_v4(), &mut operations);
create_task(uuid_v4(), &mut operations);
create_task(uuid_v4(), &mut operations);
let mut t = create_task(uuid_v4(), &mut operations);
cxx::let_cxx_string!(status = "status");
cxx::let_cxx_string!(pending = "pending");
t.update(&status, &pending, &mut operations);
rep.commit_operations(operations).unwrap();

assert_eq!(rep.all_task_data().unwrap().len(), 3);
assert_eq!(rep.pending_task_data().unwrap().len(), 1);
assert_eq!(rep.all_task_uuids().unwrap().len(), 3);
}

Expand Down
Loading