mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-06-17 01:59:49 +02:00
a30e02c18c
implements: https://github.com/meilisearch/specifications/blob/develop/text/0060-refashion-updates-apis.md linked PR: - #1889 - #1891 - #1892 - #1902 - #1906 - #1911 - #1914 - #1915 - #1916 - #1918 - #1924 - #1925 - #1926 - #1930 - #1936 - #1937 - #1942 - #1944 - #1945 - #1946 - #1947 - #1950 - #1951 - #1957 - #1959 - #1960 - #1961 - #1962 - #1964 - https://github.com/meilisearch/milli/pull/414 - https://github.com/meilisearch/milli/pull/409 - https://github.com/meilisearch/milli/pull/406 - https://github.com/meilisearch/milli/pull/418 - close #1687 - close #1786 - close #1940 - close #1948 - close #1949 - close #1932 - close #1956
50 lines
1.7 KiB
Rust
50 lines
1.7 KiB
Rust
use milli::update::UpdateBuilder;
|
|
use milli::CompressionType;
|
|
use rayon::ThreadPool;
|
|
|
|
use crate::options::IndexerOpts;
|
|
|
|
pub struct UpdateHandler {
|
|
max_nb_chunks: Option<usize>,
|
|
chunk_compression_level: Option<u32>,
|
|
thread_pool: ThreadPool,
|
|
log_frequency: usize,
|
|
max_memory: Option<usize>,
|
|
chunk_compression_type: CompressionType,
|
|
}
|
|
|
|
impl UpdateHandler {
|
|
pub fn new(opt: &IndexerOpts) -> anyhow::Result<Self> {
|
|
let thread_pool = rayon::ThreadPoolBuilder::new()
|
|
.num_threads(opt.indexing_jobs.unwrap_or(num_cpus::get() / 2))
|
|
.build()?;
|
|
|
|
Ok(Self {
|
|
max_nb_chunks: opt.max_nb_chunks,
|
|
chunk_compression_level: opt.chunk_compression_level,
|
|
thread_pool,
|
|
log_frequency: opt.log_every_n,
|
|
max_memory: opt.max_memory.map(|m| m.get_bytes() as usize),
|
|
chunk_compression_type: opt.chunk_compression_type,
|
|
})
|
|
}
|
|
|
|
pub fn update_builder(&self) -> UpdateBuilder {
|
|
// We prepare the update by using the update builder.
|
|
let mut update_builder = UpdateBuilder::new();
|
|
if let Some(max_nb_chunks) = self.max_nb_chunks {
|
|
update_builder.max_nb_chunks(max_nb_chunks);
|
|
}
|
|
if let Some(chunk_compression_level) = self.chunk_compression_level {
|
|
update_builder.chunk_compression_level(chunk_compression_level);
|
|
}
|
|
update_builder.thread_pool(&self.thread_pool);
|
|
update_builder.log_every_n(self.log_frequency);
|
|
if let Some(max_memory) = self.max_memory {
|
|
update_builder.max_memory(max_memory);
|
|
}
|
|
update_builder.chunk_compression_type(self.chunk_compression_type);
|
|
update_builder
|
|
}
|
|
}
|