Repository: meilisearch/meilisearch
File: meilisearch/src/routes/indexes/documents.rs (Rust)

Code before:
        Some(("application", "x-ndjson")) => PayloadType::Ndjson,
        Some(("text", "csv")) => PayloadType::Csv,
        Some((type_, subtype)) => {
            return Err(MeilisearchHttpError::InvalidContentType(
                format!("{}/{}", type_, subtype),
                ACCEPTED_CONTENT_TYPE.clone(),
            ))
        }
        None => {
            return Err(MeilisearchHttpError::MissingContentType(ACCEPTED_CONTENT_TYPE.clone()))
        }
    };

    // is your indexUid valid?
    let index_uid = IndexUid::try_from(index_uid)?.into_inner();

    let (uuid, mut update_file) = index_scheduler.create_update_file()?;

    let temp_file = match tempfile() {
        Ok(temp_file) => temp_file,
        Err(e) => {
            return Err(MeilisearchHttpError::Payload(ReceivePayloadErr(Box::new(e))));
        }
    };

    let mut buffer = File::from_std(temp_file);

    let mut buffer_write_size: usize = 0;
    while let Some(bytes) = body.next().await {
        let byte = &bytes?;

        if byte.is_empty() && buffer_write_size == 0 {
            return Err(MeilisearchHttpError::MissingPayload(format));
        }

        match buffer.write_all(byte).await {
            Ok(()) => buffer_write_size += 1,
            Err(e) => {
                return Err(MeilisearchHttpError::Payload(ReceivePayloadErr(Box::new(e))));
            }
        };
    }

    if let Err(e) = buffer.flush().await {
        return Err(MeilisearchHttpError::Payload(ReceivePayloadErr(Box::new(e))));
    }

    if buffer_write_size == 0 {
        return Err(MeilisearchHttpError::MissingPayload(format));
    }


Review comment (performance):
> Oops, also second big comment, for the async part we should definitely use an AsyncBufWriter or we're going to have terrible performances: https://docs.rs/tokio/latest/tokio/io/struct.BufWriter.html !

I think we lost this change? Or I forgot about it and approved the last time :grimacing: 

```suggestion
    let async_file = File::from_std(temp_file);
    let mut buffer = BufWriter::new(async_file);
```

Code after:
        Some(("application", "x-ndjson")) => PayloadType::Ndjson,
        Some(("text", "csv")) => PayloadType::Csv,
        Some((type_, subtype)) => {
            return Err(MeilisearchHttpError::InvalidContentType(
                format!("{}/{}", type_, subtype),
                ACCEPTED_CONTENT_TYPE.clone(),
            ))
        }
        None => {
            return Err(MeilisearchHttpError::MissingContentType(ACCEPTED_CONTENT_TYPE.clone()))
        }
    };

    // is your indexUid valid?
    let index_uid = IndexUid::try_from(index_uid)?.into_inner();

    let (uuid, mut update_file) = index_scheduler.create_update_file()?;

    let temp_file = match tempfile() {
        Ok(temp_file) => temp_file,
        Err(e) => {
            return Err(MeilisearchHttpError::Payload(ReceivePayloadErr(Box::new(e))));
        }
    };

    let async_file = File::from_std(temp_file);
    let mut buffer = BufWriter::new(async_file);

    let mut buffer_write_size: usize = 0;
    while let Some(bytes) = body.next().await {
        let byte = &bytes?;

        if byte.is_empty() && buffer_write_size == 0 {
            return Err(MeilisearchHttpError::MissingPayload(format));
        }

        match buffer.write_all(byte).await {
            Ok(()) => buffer_write_size += 1,
            Err(e) => {
                return Err(MeilisearchHttpError::Payload(ReceivePayloadErr(Box::new(e))));
            }
        };
    }

    if let Err(e) = buffer.flush().await {
        return Err(MeilisearchHttpError::Payload(ReceivePayloadErr(Box::new(e))));
    }

    if buffer_write_size == 0 {
        return Err(MeilisearchHttpError::MissingPayload(format));
    }