Repository: meilisearch/meilisearch
File: meilisearch-lib/src/update_file_store.rs (Rust)

Code before:
        pub fn snapshot(&self, uuid: Uuid, dst: impl AsRef<Path>) -> Result<()> {
            let src = self.path.join(uuid.to_string());
            let mut dst = dst.as_ref().join(UPDATE_FILES_PATH);
            std::fs::create_dir_all(&dst)?;
            dst.push(uuid.to_string());
            std::fs::copy(src, dst)?;
            Ok(())
        }

        /// Peforms a dump of the given update file uuid into the provided dump path.
        pub fn dump(&self, uuid: Uuid, dump_path: impl AsRef<Path>) -> Result<()> {
            println!("HERE1");
            let uuid_string = uuid.to_string();
            let update_file_path = self.path.join(&uuid_string);
            let mut dst = dump_path.as_ref().join(UPDATE_FILES_PATH);
            std::fs::create_dir_all(&dst)?;
            println!("HERE3");
            dst.push(&uuid_string);

            println!("trying to open {}", &update_file_path.display());
            let update_file = File::open(update_file_path)?;
            println!("HERE2");
            let mut dst_file = NamedTempFile::new_in(&dump_path)?;
            println!("HERE4");
            let mut document_reader = DocumentBatchReader::from_reader(update_file)?;
            println!("HERE5");

            let mut document_buffer = Map::new();
            // TODO: we need to find a way to do this more efficiently. (create a custom serializer
            // for jsonl for example...)
            while let Some((index, document)) = document_reader.next_document_with_index()? {
                for (field_id, content) in document.iter() {
                    if let Some(field_name) = index.name(field_id) {
                        let content = serde_json::from_slice(content)?;
                        document_buffer.insert(field_name.to_string(), content);
                    }
                }

                serde_json::to_writer(&mut dst_file, &document_buffer)?;
                dst_file.write_all(b"\n")?;
                document_buffer.clear();
            }

            dst_file.persist(dst)?;

            Ok(())
        }

        pub fn get_size(&self, uuid: Uuid) -> Result<u64> {
            Ok(self.get_update(uuid)?.metadata()?.len())
        }

Review comment (performance):
```suggestion
            dst.push(&uuid_string);

            let update_file = File::open(update_file_path)?;
            let mut dst_file = NamedTempFile::new_in(&dump_path)?;
            let mut document_reader = DocumentBatchReader::from_reader(update_file)?;
```

Code after:
            let src = self.path.join(uuid.to_string());
            let mut dst = dst.as_ref().join(UPDATE_FILES_PATH);
            std::fs::create_dir_all(&dst)?;
            dst.push(uuid.to_string());
            std::fs::copy(src, dst)?;
            Ok(())
        }

        /// Peforms a dump of the given update file uuid into the provided dump path.
        pub fn dump(&self, uuid: Uuid, dump_path: impl AsRef<Path>) -> Result<()> {
            let uuid_string = uuid.to_string();
            let update_file_path = self.path.join(&uuid_string);
            let mut dst = dump_path.as_ref().join(UPDATE_FILES_PATH);
            std::fs::create_dir_all(&dst)?;
            dst.push(&uuid_string);

            let update_file = File::open(update_file_path)?;
            let mut dst_file = NamedTempFile::new_in(&dump_path)?;
            let mut document_reader = DocumentBatchReader::from_reader(update_file)?;

            let mut document_buffer = Map::new();
            // TODO: we need to find a way to do this more efficiently. (create a custom serializer
            // for jsonl for example...)
            while let Some((index, document)) = document_reader.next_document_with_index()? {
                for (field_id, content) in document.iter() {
                    if let Some(field_name) = index.name(field_id) {
                        let content = serde_json::from_slice(content)?;
                        document_buffer.insert(field_name.to_string(), content);
                    }
                }

                serde_json::to_writer(&mut dst_file, &document_buffer)?;
                dst_file.write_all(b"\n")?;
                document_buffer.clear();
            }

            dst_file.persist(dst)?;

            Ok(())
        }

        pub fn get_size(&self, uuid: Uuid) -> Result<u64> {
            Ok(self.get_update(uuid)?.metadata()?.len())
        }

        pub async fn delete(&self, uuid: Uuid) -> Result<()> {
            let path = self.path.join(uuid.to_string());
            tokio::fs::remove_file(path).await?;
            Ok(())
        }
    }