mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-01-31 07:23:15 +08:00
clippy + fmt
This commit is contained in:
parent
b000ae7614
commit
834995b130
@ -1,8 +1,8 @@
|
||||
use milli::update::{IndexDocumentsMethod, UpdateFormat};
|
||||
|
||||
use crate::{Data, Payload};
|
||||
use crate::index::{Checked, Settings};
|
||||
use crate::index_controller::{error::Result, IndexMetadata, IndexSettings, UpdateStatus};
|
||||
use crate::{Data, Payload};
|
||||
|
||||
impl Data {
|
||||
pub async fn add_documents(
|
||||
|
@ -103,7 +103,7 @@ impl ErrorCode for MilliError<'_> {
|
||||
milli::Error::UserError(ref error) => {
|
||||
match error {
|
||||
// TODO: wait for spec for new error codes.
|
||||
| UserError::Csv(_)
|
||||
UserError::Csv(_)
|
||||
| UserError::SerdeJson(_)
|
||||
| UserError::MaxDatabaseSizeReached
|
||||
| UserError::InvalidCriterionName { .. }
|
||||
@ -148,9 +148,10 @@ impl ErrorCode for PayloadError {
|
||||
PayloadError::Json(err) => match err {
|
||||
JsonPayloadError::Overflow => Code::PayloadTooLarge,
|
||||
JsonPayloadError::ContentType => Code::UnsupportedMediaType,
|
||||
JsonPayloadError::Payload(aweb::error::PayloadError::Overflow) => Code::PayloadTooLarge,
|
||||
JsonPayloadError::Deserialize(_)
|
||||
| JsonPayloadError::Payload(_) => Code::BadRequest,
|
||||
JsonPayloadError::Payload(aweb::error::PayloadError::Overflow) => {
|
||||
Code::PayloadTooLarge
|
||||
}
|
||||
JsonPayloadError::Deserialize(_) | JsonPayloadError::Payload(_) => Code::BadRequest,
|
||||
JsonPayloadError::Serialize(_) => Code::Internal,
|
||||
_ => Code::Internal,
|
||||
},
|
||||
|
@ -3,7 +3,7 @@ use std::io::{BufRead, BufReader, Write};
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{Context, bail};
|
||||
use anyhow::{bail, Context};
|
||||
use heed::RoTxn;
|
||||
use indexmap::IndexMap;
|
||||
use milli::update::{IndexDocumentsMethod, UpdateFormat::JsonStream};
|
||||
|
@ -13,7 +13,7 @@ use serde_json::{Map, Value};
|
||||
use crate::helpers::EnvSizer;
|
||||
use error::Result;
|
||||
|
||||
pub use search::{SearchQuery, SearchResult, DEFAULT_SEARCH_LIMIT, default_crop_length};
|
||||
pub use search::{default_crop_length, SearchQuery, SearchResult, DEFAULT_SEARCH_LIMIT};
|
||||
pub use updates::{Checked, Facets, Settings, Unchecked};
|
||||
|
||||
use self::error::IndexError;
|
||||
|
@ -233,8 +233,8 @@ impl Index {
|
||||
fn compute_matches<A: AsRef<[u8]>>(
|
||||
matcher: &impl Matcher,
|
||||
document: &Document,
|
||||
analyzer: &Analyzer<A>
|
||||
) -> MatchesInfo {
|
||||
analyzer: &Analyzer<A>,
|
||||
) -> MatchesInfo {
|
||||
let mut matches = BTreeMap::new();
|
||||
|
||||
for (key, value) in document {
|
||||
@ -1174,6 +1174,9 @@ mod test {
|
||||
let analyzer = Analyzer::new(config);
|
||||
|
||||
let matches = compute_matches(&matcher, &value, &analyzer);
|
||||
assert_eq!(format!("{:?}", matches), r##"{"about": [MatchInfo { start: 0, length: 6 }, MatchInfo { start: 31, length: 7 }, MatchInfo { start: 191, length: 7 }, MatchInfo { start: 225, length: 7 }, MatchInfo { start: 233, length: 6 }], "color": [MatchInfo { start: 0, length: 3 }]}"##);
|
||||
assert_eq!(
|
||||
format!("{:?}", matches),
|
||||
r##"{"about": [MatchInfo { start: 0, length: 6 }, MatchInfo { start: 31, length: 7 }, MatchInfo { start: 191, length: 7 }, MatchInfo { start: 225, length: 7 }, MatchInfo { start: 233, length: 6 }], "color": [MatchInfo { start: 0, length: 3 }]}"##
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ use uuid_resolver::{error::UuidResolverError, UuidResolverHandle};
|
||||
|
||||
use crate::index::{Checked, Document, SearchQuery, SearchResult, Settings};
|
||||
use crate::option::Opt;
|
||||
use error::Result;
|
||||
use crate::Payload;
|
||||
use error::Result;
|
||||
|
||||
use self::dump_actor::load_dump;
|
||||
use self::error::IndexControllerError;
|
||||
|
@ -137,7 +137,10 @@ where
|
||||
.open(&path)
|
||||
.await?;
|
||||
|
||||
async fn write_to_file<D>(file: &mut fs::File, mut payload: mpsc::Receiver<PayloadData<D>>) -> Result<usize>
|
||||
async fn write_to_file<D>(
|
||||
file: &mut fs::File,
|
||||
mut payload: mpsc::Receiver<PayloadData<D>>,
|
||||
) -> Result<usize>
|
||||
where
|
||||
D: AsRef<[u8]> + Sized + 'static,
|
||||
{
|
||||
@ -160,7 +163,7 @@ where
|
||||
}
|
||||
Err(e) => {
|
||||
fs::remove_file(&path).await?;
|
||||
return Err(e)
|
||||
return Err(e);
|
||||
}
|
||||
_ => {
|
||||
fs::remove_file(&path).await?;
|
||||
|
@ -52,11 +52,9 @@ impl ErrorCode for UpdateActorError {
|
||||
UpdateActorError::IndexActor(e) => e.error_code(),
|
||||
UpdateActorError::FatalUpdateStoreError => Code::Internal,
|
||||
UpdateActorError::InvalidPayload(_) => Code::BadRequest,
|
||||
UpdateActorError::PayloadError(error) => {
|
||||
match error {
|
||||
actix_http::error::PayloadError::Overflow => Code::PayloadTooLarge,
|
||||
_ => Code::Internal,
|
||||
}
|
||||
UpdateActorError::PayloadError(error) => match error {
|
||||
actix_http::error::PayloadError::Overflow => Code::PayloadTooLarge,
|
||||
_ => Code::Internal,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -572,7 +572,10 @@ fn update_uuid_to_file_path(root: impl AsRef<Path>, uuid: Uuid) -> PathBuf {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::index_controller::{UpdateResult, index_actor::{MockIndexActorHandle, error::IndexActorError}};
|
||||
use crate::index_controller::{
|
||||
index_actor::{error::IndexActorError, MockIndexActorHandle},
|
||||
UpdateResult,
|
||||
};
|
||||
|
||||
use futures::future::ok;
|
||||
|
||||
@ -651,7 +654,9 @@ mod test {
|
||||
if processing.id() == 0 {
|
||||
Box::pin(ok(Ok(processing.process(UpdateResult::Other))))
|
||||
} else {
|
||||
Box::pin(ok(Err(processing.fail(IndexActorError::ExistingPrimaryKey.into()))))
|
||||
Box::pin(ok(Err(
|
||||
processing.fail(IndexActorError::ExistingPrimaryKey.into())
|
||||
)))
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -3,7 +3,10 @@ use milli::update::{DocumentAdditionResult, IndexDocumentsMethod, UpdateFormat};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{error::ResponseError, index::{Settings, Unchecked}};
|
||||
use crate::{
|
||||
error::ResponseError,
|
||||
index::{Settings, Unchecked},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum UpdateResult {
|
||||
|
@ -10,13 +10,19 @@ pub mod routes;
|
||||
#[cfg(all(not(debug_assertions), feature = "analytics"))]
|
||||
pub mod analytics;
|
||||
|
||||
use std::{pin::Pin, task::{Context, Poll}};
|
||||
use std::{
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
pub use self::data::Data;
|
||||
use futures::{Stream, future::{Ready, ready}};
|
||||
use futures::{
|
||||
future::{ready, Ready},
|
||||
Stream,
|
||||
};
|
||||
pub use option::Opt;
|
||||
|
||||
use actix_web::{FromRequest, HttpRequest, dev, error::PayloadError, web};
|
||||
use actix_web::{dev, error::PayloadError, web, FromRequest, HttpRequest};
|
||||
|
||||
pub fn configure_data(config: &mut web::ServiceConfig, data: Data) {
|
||||
let http_payload_size_limit = data.http_payload_size_limit();
|
||||
@ -40,12 +46,12 @@ pub fn dashboard(config: &mut web::ServiceConfig, enable_frontend: bool) {
|
||||
use actix_web_static_files::Resource;
|
||||
use actix_web::HttpResponse;
|
||||
|
||||
mod dashboard {
|
||||
mod generated {
|
||||
include!(concat!(env!("OUT_DIR"), "/generated.rs"));
|
||||
}
|
||||
|
||||
if enable_frontend {
|
||||
let generated = dashboard::generate();
|
||||
let generated = generated::generate();
|
||||
let mut scope = web::scope("/");
|
||||
// Generate routes for mini-dashboard assets
|
||||
for (path, resource) in generated.into_iter() {
|
||||
@ -80,7 +86,7 @@ macro_rules! create_app {
|
||||
use actix_web::App;
|
||||
use actix_web::{middleware, web};
|
||||
use meilisearch_http::routes::*;
|
||||
use meilisearch_http::{dashboard, configure_data};
|
||||
use meilisearch_http::{configure_data, dashboard};
|
||||
|
||||
App::new()
|
||||
.configure(|s| configure_data(s, $data.clone()))
|
||||
@ -95,15 +101,17 @@ macro_rules! create_app {
|
||||
.configure(|s| dashboard(s, $enable_frontend))
|
||||
.wrap(
|
||||
Cors::default()
|
||||
.send_wildcard()
|
||||
.allowed_headers(vec!["content-type", "x-meili-api-key"])
|
||||
.allow_any_origin()
|
||||
.allow_any_method()
|
||||
.max_age(86_400), // 24h
|
||||
.send_wildcard()
|
||||
.allowed_headers(vec!["content-type", "x-meili-api-key"])
|
||||
.allow_any_origin()
|
||||
.allow_any_method()
|
||||
.max_age(86_400), // 24h
|
||||
)
|
||||
.wrap(middleware::Logger::default())
|
||||
.wrap(middleware::Compress::default())
|
||||
.wrap(middleware::NormalizePath::new(middleware::TrailingSlash::Trim))
|
||||
.wrap(middleware::NormalizePath::new(
|
||||
middleware::TrailingSlash::Trim,
|
||||
))
|
||||
}};
|
||||
}
|
||||
|
||||
@ -117,12 +125,14 @@ pub struct PayloadConfig {
|
||||
}
|
||||
|
||||
impl PayloadConfig {
|
||||
pub fn new(limit: usize) -> Self { Self { limit } }
|
||||
pub fn new(limit: usize) -> Self {
|
||||
Self { limit }
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PayloadConfig {
|
||||
fn default() -> Self {
|
||||
Self { limit: 256 * 1024 }
|
||||
Self { limit: 256 * 1024 }
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,8 +145,14 @@ impl FromRequest for Payload {
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
||||
let limit = req.app_data::<PayloadConfig>().map(|c| c.limit).unwrap_or(Self::Config::default().limit);
|
||||
ready(Ok(Payload { payload: payload.take(), limit }))
|
||||
let limit = req
|
||||
.app_data::<PayloadConfig>()
|
||||
.map(|c| c.limit)
|
||||
.unwrap_or(Self::Config::default().limit);
|
||||
ready(Ok(Payload {
|
||||
payload: payload.take(),
|
||||
limit,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,19 +162,15 @@ impl Stream for Payload {
|
||||
#[inline]
|
||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||
match Pin::new(&mut self.payload).poll_next(cx) {
|
||||
Poll::Ready(Some(result)) => {
|
||||
match result {
|
||||
Ok(bytes) => {
|
||||
match self.limit.checked_sub(bytes.len()) {
|
||||
Some(new_limit) => {
|
||||
self.limit = new_limit;
|
||||
Poll::Ready(Some(Ok(bytes)))
|
||||
}
|
||||
None => Poll::Ready(Some(Err(PayloadError::Overflow))),
|
||||
}
|
||||
Poll::Ready(Some(result)) => match result {
|
||||
Ok(bytes) => match self.limit.checked_sub(bytes.len()) {
|
||||
Some(new_limit) => {
|
||||
self.limit = new_limit;
|
||||
Poll::Ready(Some(Ok(bytes)))
|
||||
}
|
||||
x => Poll::Ready(Some(x)),
|
||||
}
|
||||
None => Poll::Ready(Some(Err(PayloadError::Overflow))),
|
||||
},
|
||||
x => Poll::Ready(Some(x)),
|
||||
},
|
||||
otherwise => otherwise,
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use std::env;
|
||||
|
||||
use actix_web::HttpServer;
|
||||
use main_error::MainError;
|
||||
use meilisearch_http::{Data, Opt, create_app};
|
||||
use meilisearch_http::{create_app, Data, Opt};
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[cfg(all(not(debug_assertions), feature = "analytics"))]
|
||||
@ -83,8 +83,8 @@ async fn run_http(data: Data, opt: Opt) -> Result<(), Box<dyn std::error::Error>
|
||||
.bind_rustls(opt.http_addr, config)?
|
||||
.run()
|
||||
.await?;
|
||||
} else {
|
||||
http_server.bind(opt.http_addr)?.run().await?;
|
||||
} else {
|
||||
http_server.bind(opt.http_addr)?.run().await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use serde_json::Value;
|
||||
|
||||
use crate::error::ResponseError;
|
||||
use crate::helpers::Authentication;
|
||||
use crate::index::{SearchQuery, default_crop_length, DEFAULT_SEARCH_LIMIT};
|
||||
use crate::index::{default_crop_length, SearchQuery, DEFAULT_SEARCH_LIMIT};
|
||||
use crate::routes::IndexParam;
|
||||
use crate::Data;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user