Repository: meilisearch/meilisearch
File: dump/src/reader/v5/mod.rs (Rust)

Code before:
        index_metadata: &meta::IndexMeta,
        tasks: BufReader<File>,
    ) -> Result<Self> {
        let meta = File::open(path.join("meta.json"))?;
        let meta: meta::DumpMeta = serde_json::from_reader(meta)?;

        let mut created_at = None;
        let mut updated_at = None;

        for line in tasks.lines() {
            let task: Task = serde_json::from_str(&line?)?;

            if *task.index_uid().unwrap_or_default().to_string() == name {
                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 {
            uid: name,
            primary_key: meta.primary_key,
            created_at: created_at.unwrap_or_else(OffsetDateTime::now_utc),
            updated_at: updated_at.unwrap_or_else(OffsetDateTime::now_utc),
        };

        let ret = V5IndexReader {
            metadata,
            settings: meta.settings.check(),
            documents: BufReader::new(File::open(path.join("documents.jsonl"))?),
        };

        Ok(ret)
    }

    pub fn metadata(&self) -> &IndexMetadata {
        &self.metadata
    }

    pub fn documents(&mut self) -> Result<impl Iterator<Item = Result<Document>> + '_> {
        Ok((&mut self.documents)

Review comment (suggestion):
```suggestion
                if task.id as usize == index_metadata.creation_task_id {
                    created_at = task.created_at();
                    break;
                }
```

Code after:
        index_metadata: &meta::IndexMeta,
        tasks: BufReader<File>,
    ) -> Result<Self> {
        let meta = File::open(path.join("meta.json"))?;
        let meta: meta::DumpMeta = serde_json::from_reader(meta)?;

        let mut created_at = None;
        let mut updated_at = None;

        for line in tasks.lines() {
            let task: Task = serde_json::from_str(&line?)?;

            if *task.index_uid().unwrap_or_default().to_string() == name {
                if updated_at.is_none() {
                    updated_at = task.processed_at()
                }

                if task.id as usize == index_metadata.creation_task_id {
                    created_at = task.created_at();

                    break;
                }
            }
        }

        let metadata = IndexMetadata {
            uid: name,
            primary_key: meta.primary_key,
            created_at: created_at.unwrap_or_else(OffsetDateTime::now_utc),
            updated_at: updated_at.unwrap_or_else(OffsetDateTime::now_utc),
        };

        let ret = V5IndexReader {
            metadata,
            settings: meta.settings.check(),
            documents: BufReader::new(File::open(path.join("documents.jsonl"))?),
        };

        Ok(ret)
    }

    pub fn metadata(&self) -> &IndexMetadata {
        &self.metadata
    }

    pub fn documents(&mut self) -> Result<impl Iterator<Item = Result<Document>> + '_> {
        Ok((&mut self.documents)
            .lines()
            .map(|line| -> Result<_> { Ok(serde_json::from_str(&line?)?) }))
    }