mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-01 17:15:46 +01:00
Reimplement v5 date extraction.
Indeed, before this patch the implementation wasn't correct.
This commit is contained in:
parent
13fb5ce974
commit
528a944997
@ -142,7 +142,10 @@ 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(File::open(&self.dump.path().join("updates").join("data.jsonl")).unwrap()),
|
&index.index_meta,
|
||||||
|
BufReader::new(
|
||||||
|
File::open(&self.dump.path().join("updates").join("data.jsonl")).unwrap(),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@ -191,31 +194,43 @@ pub struct V5IndexReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl V5IndexReader {
|
impl V5IndexReader {
|
||||||
pub fn new(name: String, path: &Path, tasks: BufReader<File>) -> Result<Self> {
|
pub fn new(
|
||||||
|
name: String,
|
||||||
|
path: &Path,
|
||||||
|
index_metadata: &meta::IndexMeta,
|
||||||
|
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![];
|
let mut created_at = None;
|
||||||
|
let mut updated_at = None;
|
||||||
|
|
||||||
for line in tasks.lines() {
|
for line in tasks.lines() {
|
||||||
let task: Task = serde_json::from_str(&line?)?;
|
let task: Task = serde_json::from_str(&line?)?;
|
||||||
|
|
||||||
if task.index_uid().unwrap_or_default() == name {
|
if task.index_uid().unwrap_or_default().to_string() == name {
|
||||||
index_tasks.push(task)
|
if updated_at.is_none() {
|
||||||
|
updated_at = task.updated_at()
|
||||||
|
}
|
||||||
|
|
||||||
|
if created_at.is_none() {
|
||||||
|
created_at = task.created_at()
|
||||||
|
}
|
||||||
|
|
||||||
|
if task.id as usize == index_metadata.creation_task_id {
|
||||||
|
created_at = task.processed_at();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let metadata = IndexMetadata {
|
let metadata = IndexMetadata {
|
||||||
uid: name,
|
uid: name,
|
||||||
primary_key: meta.primary_key,
|
primary_key: meta.primary_key,
|
||||||
created_at: match index_tasks.first().unwrap().events.first() {
|
created_at: created_at.unwrap_or_else(OffsetDateTime::now_utc),
|
||||||
Some(TaskEvent::Created(ts)) => *ts,
|
updated_at: updated_at.unwrap_or_else(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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user