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:
@@ -260,10 +260,10 @@ impl<'r> TaskMut<'r> {
|
|||||||
fn lastmod(&mut self) -> anyhow::Result<()> {
|
fn lastmod(&mut self) -> anyhow::Result<()> {
|
||||||
if !self.updated_modified {
|
if !self.updated_modified {
|
||||||
let now = format!("{}", Utc::now().timestamp());
|
let now = format!("{}", Utc::now().timestamp());
|
||||||
self.replica
|
|
||||||
.update_task(self.task.uuid, "modified", Some(now.clone()))?;
|
|
||||||
trace!("task {}: set property modified={:?}", self.task.uuid, now);
|
trace!("task {}: set property modified={:?}", self.task.uuid, now);
|
||||||
self.task.taskmap.insert(String::from("modified"), now);
|
self.task.taskmap =
|
||||||
|
self.replica
|
||||||
|
.update_task(self.task.uuid, "modified", Some(now.clone()))?;
|
||||||
self.updated_modified = true;
|
self.updated_modified = true;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -276,16 +276,17 @@ impl<'r> TaskMut<'r> {
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let property = property.into();
|
let property = property.into();
|
||||||
self.lastmod()?;
|
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);
|
trace!("task {}: set property {}={:?}", self.task.uuid, property, v);
|
||||||
self.task.taskmap.insert(property, v);
|
|
||||||
} else {
|
} else {
|
||||||
trace!("task {}: remove property {}", self.task.uuid, property);
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,18 +295,7 @@ impl<'r> TaskMut<'r> {
|
|||||||
property: &str,
|
property: &str,
|
||||||
value: Option<DateTime<Utc>>,
|
value: Option<DateTime<Utc>>,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
self.lastmod()?;
|
self.set_string(property, value.map(|v| v.timestamp().to_string()))
|
||||||
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(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used by tests to ensure that updates are properly written
|
/// Used by tests to ensure that updates are properly written
|
||||||
|
|||||||
Reference in New Issue
Block a user