diff --git a/dump/src/reader/v4/mod.rs b/dump/src/reader/v4/mod.rs index 3aad71ddb..c335d4289 100644 --- a/dump/src/reader/v4/mod.rs +++ b/dump/src/reader/v4/mod.rs @@ -23,6 +23,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; // everything related to the settings @@ -100,6 +101,7 @@ impl V4Reader { V4IndexReader::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()), ) })) } @@ -147,16 +149,31 @@ pub struct V4IndexReader { } impl V4IndexReader { - pub fn new(name: String, path: &Path) -> Result { + pub fn new(name: String, path: &Path, tasks: BufReader) -> Result { let meta = File::open(path.join("meta.json"))?; let meta: DumpMeta = serde_json::from_reader(meta)?; + let mut index_tasks: Vec = vec![]; + + for line in tasks.lines() { + let task: Task = serde_json::from_str(&line?)?; + + if task.index_uid.to_string() == 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 = V4IndexReader {