mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-22 18:17:39 +08:00
rename the update-file-store to file-store since it can store any kind of file
This commit is contained in:
parent
76597fc382
commit
48138c21a9
@ -1,4 +1,4 @@
|
|||||||
use std::fs::File;
|
use std::fs::File as StdFile;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ pub enum Error {
|
|||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
impl Deref for UpdateFile {
|
impl Deref for File {
|
||||||
type Target = NamedTempFile;
|
type Target = NamedTempFile;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
@ -25,7 +25,7 @@ impl Deref for UpdateFile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DerefMut for UpdateFile {
|
impl DerefMut for File {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
&mut self.file
|
&mut self.file
|
||||||
}
|
}
|
||||||
@ -33,33 +33,33 @@ impl DerefMut for UpdateFile {
|
|||||||
|
|
||||||
// #[cfg_attr(test, faux::create)]
|
// #[cfg_attr(test, faux::create)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct UpdateFileStore {
|
pub struct FileStore {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg_attr(test, faux::methods)]
|
// #[cfg_attr(test, faux::methods)]
|
||||||
impl UpdateFileStore {
|
impl FileStore {
|
||||||
pub fn new(path: impl AsRef<Path>) -> Result<UpdateFileStore> {
|
pub fn new(path: impl AsRef<Path>) -> Result<FileStore> {
|
||||||
let path = path.as_ref().join(UPDATE_FILES_PATH);
|
let path = path.as_ref().join(UPDATE_FILES_PATH);
|
||||||
std::fs::create_dir_all(&path)?;
|
std::fs::create_dir_all(&path)?;
|
||||||
Ok(UpdateFileStore { path })
|
Ok(FileStore { path })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new temporary update file.
|
/// Creates a new temporary update file.
|
||||||
/// A call to `persist` is needed to persist the file in the database.
|
/// A call to `persist` is needed to persist the file in the database.
|
||||||
pub fn new_update(&self) -> Result<(Uuid, UpdateFile)> {
|
pub fn new_update(&self) -> Result<(Uuid, File)> {
|
||||||
let file = NamedTempFile::new_in(&self.path)?;
|
let file = NamedTempFile::new_in(&self.path)?;
|
||||||
let uuid = Uuid::new_v4();
|
let uuid = Uuid::new_v4();
|
||||||
let path = self.path.join(uuid.to_string());
|
let path = self.path.join(uuid.to_string());
|
||||||
let update_file = UpdateFile { file, path };
|
let update_file = File { file, path };
|
||||||
|
|
||||||
Ok((uuid, update_file))
|
Ok((uuid, update_file))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the file corresponding to the requested uuid.
|
/// Returns the file corresponding to the requested uuid.
|
||||||
pub fn get_update(&self, uuid: Uuid) -> Result<File> {
|
pub fn get_update(&self, uuid: Uuid) -> Result<StdFile> {
|
||||||
let path = self.path.join(uuid.to_string());
|
let path = self.path.join(uuid.to_string());
|
||||||
let file = File::open(path)?;
|
let file = StdFile::open(path)?;
|
||||||
Ok(file)
|
Ok(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,12 +84,12 @@ impl UpdateFileStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UpdateFile {
|
pub struct File {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
file: NamedTempFile,
|
file: NamedTempFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UpdateFile {
|
impl File {
|
||||||
pub fn persist(self) -> Result<()> {
|
pub fn persist(self) -> Result<()> {
|
||||||
self.file.persist(&self.path)?;
|
self.file.persist(&self.path)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -13,7 +13,7 @@ use uuid::Uuid;
|
|||||||
|
|
||||||
use super::error::{IndexError, Result};
|
use super::error::{IndexError, Result};
|
||||||
use super::index::{Index, IndexMeta};
|
use super::index::{Index, IndexMeta};
|
||||||
use file_store::UpdateFileStore;
|
use file_store::FileStore;
|
||||||
|
|
||||||
fn serialize_with_wildcard<S>(
|
fn serialize_with_wildcard<S>(
|
||||||
field: &Setting<Vec<String>>,
|
field: &Setting<Vec<String>>,
|
||||||
@ -297,7 +297,7 @@ impl Index {
|
|||||||
&self,
|
&self,
|
||||||
method: IndexDocumentsMethod,
|
method: IndexDocumentsMethod,
|
||||||
primary_key: Option<String>,
|
primary_key: Option<String>,
|
||||||
file_store: UpdateFileStore,
|
file_store: FileStore,
|
||||||
contents: impl IntoIterator<Item = Uuid>,
|
contents: impl IntoIterator<Item = Uuid>,
|
||||||
) -> Result<Vec<Result<DocumentAdditionResult>>> {
|
) -> Result<Vec<Result<DocumentAdditionResult>>> {
|
||||||
trace!("performing document addition");
|
trace!("performing document addition");
|
||||||
|
@ -8,7 +8,7 @@ mod utils;
|
|||||||
|
|
||||||
use batch::Batch;
|
use batch::Batch;
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
use file_store::UpdateFileStore;
|
use file_store::FileStore;
|
||||||
use index::Index;
|
use index::Index;
|
||||||
pub use task::Task;
|
pub use task::Task;
|
||||||
use task::{Kind, KindWithContent, Status};
|
use task::{Kind, KindWithContent, Status};
|
||||||
@ -57,7 +57,7 @@ pub struct IndexScheduler {
|
|||||||
/// The list of tasks currently processing.
|
/// The list of tasks currently processing.
|
||||||
processing_tasks: Arc<RwLock<RoaringBitmap>>,
|
processing_tasks: Arc<RwLock<RoaringBitmap>>,
|
||||||
|
|
||||||
file_store: UpdateFileStore,
|
file_store: FileStore,
|
||||||
|
|
||||||
/// The LMDB environment which the DBs are associated with.
|
/// The LMDB environment which the DBs are associated with.
|
||||||
env: Env,
|
env: Env,
|
||||||
|
Loading…
Reference in New Issue
Block a user