Extract the dates out of the dumpv4.

This patch possibly fixes #2987.

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:57:40 +01:00
parent c7caadb54e
commit ab3056cc66
No known key found for this signature in database
GPG Key ID: 0D8BFEF5515C00C6

View File

@ -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<Self> {
pub fn new(name: String, path: &Path, tasks: BufReader<File>) -> Result<Self> {
let meta = File::open(path.join("meta.json"))?;
let 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.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 {