mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 20:07:09 +02:00
Compress updates content using gzip
This commit is contained in:
parent
cd5605bb86
commit
5a23417499
3 changed files with 23 additions and 3 deletions
|
@ -10,6 +10,7 @@ use std::time::Instant;
|
|||
use std::{mem, io};
|
||||
|
||||
use askama_warp::Template;
|
||||
use async_compression::tokio_02::write::GzipEncoder;
|
||||
use flate2::read::GzDecoder;
|
||||
use futures::stream;
|
||||
use futures::{FutureExt, StreamExt};
|
||||
|
@ -340,7 +341,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
otherwise => panic!("invalid indexing method {:?}", otherwise),
|
||||
};
|
||||
|
||||
let gzipped = false;
|
||||
let gzipped = true;
|
||||
let reader = if gzipped {
|
||||
Box::new(GzDecoder::new(content))
|
||||
} else {
|
||||
|
@ -704,13 +705,17 @@ async fn main() -> anyhow::Result<()> {
|
|||
) -> Result<impl warp::Reply, warp::Rejection>
|
||||
{
|
||||
let file = tokio::task::block_in_place(tempfile::tempfile).unwrap();
|
||||
let mut file = TFile::from_std(file);
|
||||
let file = TFile::from_std(file);
|
||||
let mut encoder = GzipEncoder::new(file);
|
||||
|
||||
while let Some(result) = stream.next().await {
|
||||
let bytes = result.unwrap().to_bytes();
|
||||
file.write_all(&bytes[..]).await.unwrap();
|
||||
encoder.write_all(&bytes[..]).await.unwrap();
|
||||
}
|
||||
|
||||
encoder.shutdown().await.unwrap();
|
||||
let mut file = encoder.into_inner();
|
||||
file.sync_all().await.unwrap();
|
||||
let file = file.into_std().await;
|
||||
let mmap = unsafe { memmap::Mmap::map(&file).unwrap() };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue