mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Use the latest taskmap when modifying a task
The previous logic duplicated the action of applying an operation to the TaskDb with a "manual" application to the Task's local TaskMap. This now uses the updated TaskMap fetched from the DB, which will help to incorporate any other concurrent DB updates.
This commit is contained in:
parent
fee25fa742
commit
cefdd83d94
1 changed files with 10 additions and 20 deletions
|
@ -260,10 +260,10 @@ impl<'r> TaskMut<'r> {
|
|||
fn lastmod(&mut self) -> anyhow::Result<()> {
|
||||
if !self.updated_modified {
|
||||
let now = format!("{}", Utc::now().timestamp());
|
||||
trace!("task {}: set property modified={:?}", self.task.uuid, now);
|
||||
self.task.taskmap =
|
||||
self.replica
|
||||
.update_task(self.task.uuid, "modified", Some(now.clone()))?;
|
||||
trace!("task {}: set property modified={:?}", self.task.uuid, now);
|
||||
self.task.taskmap.insert(String::from("modified"), now);
|
||||
self.updated_modified = true;
|
||||
}
|
||||
Ok(())
|
||||
|
@ -276,16 +276,17 @@ impl<'r> TaskMut<'r> {
|
|||
) -> anyhow::Result<()> {
|
||||
let property = property.into();
|
||||
self.lastmod()?;
|
||||
self.replica
|
||||
.update_task(self.task.uuid, &property, value.as_ref())?;
|
||||
|
||||
if let Some(v) = value {
|
||||
if let Some(ref v) = value {
|
||||
trace!("task {}: set property {}={:?}", self.task.uuid, property, v);
|
||||
self.task.taskmap.insert(property, v);
|
||||
} else {
|
||||
trace!("task {}: remove property {}", self.task.uuid, property);
|
||||
self.task.taskmap.remove(&property);
|
||||
}
|
||||
|
||||
self.task.taskmap = self
|
||||
.replica
|
||||
.update_task(self.task.uuid, &property, value.as_ref())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -294,18 +295,7 @@ impl<'r> TaskMut<'r> {
|
|||
property: &str,
|
||||
value: Option<DateTime<Utc>>,
|
||||
) -> anyhow::Result<()> {
|
||||
self.lastmod()?;
|
||||
if let Some(value) = value {
|
||||
let ts = format!("{}", value.timestamp());
|
||||
self.replica
|
||||
.update_task(self.task.uuid, property, Some(ts.clone()))?;
|
||||
self.task.taskmap.insert(property.to_string(), ts);
|
||||
} else {
|
||||
self.replica
|
||||
.update_task::<_, &str>(self.task.uuid, property, None)?;
|
||||
self.task.taskmap.remove(property);
|
||||
}
|
||||
Ok(())
|
||||
self.set_string(property, value.map(|v| v.timestamp().to_string()))
|
||||
}
|
||||
|
||||
/// Used by tests to ensure that updates are properly written
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue