Extract the dates out of the dumpv5.
This patch possibly fixes
This patch introduces a way to fill the IndexMetadata.created_at
and IndexMetadata.updated_at keys from the tasks events.
This is done by reading the creation date of the first event
(created_at) and the creation date of the last event (updated_at).
@@ -56,6 +56,7 @@ pub type Checked = settings::Checked;
pub type Unchecked = settings::Unchecked;
pub type Task = tasks::Task;
+pub type TaskEvent = tasks::TaskEvent;
pub type Key = keys::Key;
// ===== Other types to clarify the code of the compat module
@@ -141,6 +142,7 @@ impl V5Reader {
V5IndexReader::new(
index.uid.clone(),
&self.dump.path().join("indexes").join(index.index_meta.uuid.to_string()),
+ BufReader::new(self.tasks.get_ref().try_clone().unwrap()),
)
}))
}
@@ -189,16 +191,31 @@ pub struct V5IndexReader {
}
impl V5IndexReader {
- pub fn new(name: String, path: &Path) -> Result<Self> {
+ pub fn new(name: String, path: &Path, tasks: BufReader<File>) -> Result<Self> {
let meta = File::open(path.join("meta.json"))?;
let meta: meta::DumpMeta = serde_json::from_reader(meta)?;
+ let mut index_tasks: Vec<Task> = vec![];
+
+ for line in tasks.lines() {
+ let task: Task = serde_json::from_str(&line?)?;
+
+ if task.index_uid().unwrap_or_default() == name {
+ index_tasks.push(task)
+ }
+ }
+
let metadata = IndexMetadata {
uid: name,
primary_key: meta.primary_key,
- // FIXME: Iterate over the whole task queue to find the creation and last update date.
- created_at: OffsetDateTime::now_utc(),
- updated_at: OffsetDateTime::now_utc(),
+ created_at: match index_tasks.first().unwrap().events.first() {
+ Some(TaskEvent::Created(ts)) => *ts,
+ _ => OffsetDateTime::now_utc(),
+ },
+ updated_at: match index_tasks.last().unwrap().events.last() {
+ Some(TaskEvent::Created(ts)) => *ts,
+ _ => OffsetDateTime::now_utc(),
+ },
};
let ret = V5IndexReader {
