Extract the dates out of the dumpv5.

This patch possibly fixes #2986.

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).
This commit is contained in:
funilrys 2022-10-31 18:18:35 +01:00
parent 9925309492
commit 61b3a29ff3
No known key found for this signature in database
GPG Key ID: 0D8BFEF5515C00C6

View File

@ -56,6 +56,7 @@ pub type Checked = settings::Checked;
pub type Unchecked = settings::Unchecked; pub type Unchecked = settings::Unchecked;
pub type Task = tasks::Task; pub type Task = tasks::Task;
pub type TaskEvent = tasks::TaskEvent;
pub type Key = keys::Key; pub type Key = keys::Key;
// ===== Other types to clarify the code of the compat module // ===== Other types to clarify the code of the compat module
@ -141,6 +142,7 @@ impl V5Reader {
V5IndexReader::new( V5IndexReader::new(
index.uid.clone(), index.uid.clone(),
&self.dump.path().join("indexes").join(index.index_meta.uuid.to_string()), &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 { 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 = File::open(path.join("meta.json"))?;
let meta: meta::DumpMeta = serde_json::from_reader(meta)?; 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 { let metadata = IndexMetadata {
uid: name, uid: name,
primary_key: meta.primary_key, primary_key: meta.primary_key,
// FIXME: Iterate over the whole task queue to find the creation and last update date. created_at: match index_tasks.first().unwrap().events.first() {
created_at: OffsetDateTime::now_utc(), Some(TaskEvent::Created(ts)) => *ts,
updated_at: OffsetDateTime::now_utc(), _ => OffsetDateTime::now_utc(),
},
updated_at: match index_tasks.last().unwrap().events.last() {
Some(TaskEvent::Created(ts)) => *ts,
_ => OffsetDateTime::now_utc(),
},
}; };
let ret = V5IndexReader { let ret = V5IndexReader {