mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 02:27:40 +08:00
fix no-analytics
This commit is contained in:
parent
f6d53e03f1
commit
0c1a3d59eb
@ -50,7 +50,7 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
let auth_controller = AuthController::new(&opt.db_path, &opt.master_key)?;
|
let auth_controller = AuthController::new(&opt.db_path, &opt.master_key)?;
|
||||||
|
|
||||||
#[cfg(all(not(debug_assertions), feature = "analytics"))]
|
#[cfg(all(not(debug_assertions), feature = "analytics"))]
|
||||||
let (analytics, user) = if opt.analytics() {
|
let (analytics, user) = if !opt.no_analytics {
|
||||||
analytics::SegmentAnalytics::new(&opt, &meilisearch).await
|
analytics::SegmentAnalytics::new(&opt, &meilisearch).await
|
||||||
} else {
|
} else {
|
||||||
analytics::MockAnalytics::new(&opt)
|
analytics::MockAnalytics::new(&opt)
|
||||||
@ -125,7 +125,7 @@ pub fn print_launch_resume(opt: &Opt, user: &str) {
|
|||||||
|
|
||||||
#[cfg(all(not(debug_assertions), feature = "analytics"))]
|
#[cfg(all(not(debug_assertions), feature = "analytics"))]
|
||||||
{
|
{
|
||||||
if opt.analytics() {
|
if !opt.no_analytics {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"
|
"
|
||||||
Thank you for using MeiliSearch!
|
Thank you for using MeiliSearch!
|
||||||
|
@ -129,16 +129,6 @@ pub struct Opt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Opt {
|
impl Opt {
|
||||||
/// Wether analytics should be enabled or not.
|
|
||||||
#[cfg(all(not(debug_assertions), feature = "analytics"))]
|
|
||||||
pub fn analytics(&self) -> bool {
|
|
||||||
match self.no_analytics {
|
|
||||||
None => true,
|
|
||||||
Some(None) => false,
|
|
||||||
Some(Some(disabled)) => !disabled,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_ssl_config(&self) -> anyhow::Result<Option<rustls::ServerConfig>> {
|
pub fn get_ssl_config(&self) -> anyhow::Result<Option<rustls::ServerConfig>> {
|
||||||
if let (Some(cert_path), Some(key_path)) = (&self.ssl_cert_path, &self.ssl_key_path) {
|
if let (Some(cert_path), Some(key_path)) = (&self.ssl_cert_path, &self.ssl_key_path) {
|
||||||
let client_auth = match &self.ssl_auth_path {
|
let client_auth = match &self.ssl_auth_path {
|
||||||
|
@ -35,15 +35,12 @@ pub struct Index<'a> {
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
impl Index<'_> {
|
impl Index<'_> {
|
||||||
pub async fn get(&self) -> (Value, StatusCode) {
|
pub async fn get(&self) -> (Value, StatusCode) {
|
||||||
let url = format!("/indexes/{}", encode(self.uid.as_ref()).to_string());
|
let url = format!("/indexes/{}", encode(self.uid.as_ref()));
|
||||||
self.service.get(url).await
|
self.service.get(url).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn load_test_set(&self) -> u64 {
|
pub async fn load_test_set(&self) -> u64 {
|
||||||
let url = format!(
|
let url = format!("/indexes/{}/documents", encode(self.uid.as_ref()));
|
||||||
"/indexes/{}/documents",
|
|
||||||
encode(self.uid.as_ref()).to_string()
|
|
||||||
);
|
|
||||||
let (response, code) = self
|
let (response, code) = self
|
||||||
.service
|
.service
|
||||||
.post_str(url, include_str!("../assets/test_set.json"))
|
.post_str(url, include_str!("../assets/test_set.json"))
|
||||||
@ -66,13 +63,13 @@ impl Index<'_> {
|
|||||||
let body = json!({
|
let body = json!({
|
||||||
"primaryKey": primary_key,
|
"primaryKey": primary_key,
|
||||||
});
|
});
|
||||||
let url = format!("/indexes/{}", encode(self.uid.as_ref()).to_string());
|
let url = format!("/indexes/{}", encode(self.uid.as_ref()));
|
||||||
|
|
||||||
self.service.put(url, body).await
|
self.service.put(url, body).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete(&self) -> (Value, StatusCode) {
|
pub async fn delete(&self) -> (Value, StatusCode) {
|
||||||
let url = format!("/indexes/{}", encode(self.uid.as_ref()).to_string());
|
let url = format!("/indexes/{}", encode(self.uid.as_ref()));
|
||||||
self.service.delete(url).await
|
self.service.delete(url).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,13 +81,10 @@ impl Index<'_> {
|
|||||||
let url = match primary_key {
|
let url = match primary_key {
|
||||||
Some(key) => format!(
|
Some(key) => format!(
|
||||||
"/indexes/{}/documents?primaryKey={}",
|
"/indexes/{}/documents?primaryKey={}",
|
||||||
encode(self.uid.as_ref()).to_string(),
|
encode(self.uid.as_ref()),
|
||||||
key
|
key
|
||||||
),
|
),
|
||||||
None => format!(
|
None => format!("/indexes/{}/documents", encode(self.uid.as_ref())),
|
||||||
"/indexes/{}/documents",
|
|
||||||
encode(self.uid.as_ref()).to_string()
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
self.service.post(url, documents).await
|
self.service.post(url, documents).await
|
||||||
}
|
}
|
||||||
@ -103,13 +97,10 @@ impl Index<'_> {
|
|||||||
let url = match primary_key {
|
let url = match primary_key {
|
||||||
Some(key) => format!(
|
Some(key) => format!(
|
||||||
"/indexes/{}/documents?primaryKey={}",
|
"/indexes/{}/documents?primaryKey={}",
|
||||||
encode(self.uid.as_ref()).to_string(),
|
encode(self.uid.as_ref()),
|
||||||
key
|
key
|
||||||
),
|
),
|
||||||
None => format!(
|
None => format!("/indexes/{}/documents", encode(self.uid.as_ref())),
|
||||||
"/indexes/{}/documents",
|
|
||||||
encode(self.uid.as_ref()).to_string()
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
self.service.put(url, documents).await
|
self.service.put(url, documents).await
|
||||||
}
|
}
|
||||||
@ -145,19 +136,12 @@ impl Index<'_> {
|
|||||||
id: u64,
|
id: u64,
|
||||||
_options: Option<GetDocumentOptions>,
|
_options: Option<GetDocumentOptions>,
|
||||||
) -> (Value, StatusCode) {
|
) -> (Value, StatusCode) {
|
||||||
let url = format!(
|
let url = format!("/indexes/{}/documents/{}", encode(self.uid.as_ref()), id);
|
||||||
"/indexes/{}/documents/{}",
|
|
||||||
encode(self.uid.as_ref()).to_string(),
|
|
||||||
id
|
|
||||||
);
|
|
||||||
self.service.get(url).await
|
self.service.get(url).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_all_documents(&self, options: GetAllDocumentsOptions) -> (Value, StatusCode) {
|
pub async fn get_all_documents(&self, options: GetAllDocumentsOptions) -> (Value, StatusCode) {
|
||||||
let mut url = format!(
|
let mut url = format!("/indexes/{}/documents?", encode(self.uid.as_ref()));
|
||||||
"/indexes/{}/documents?",
|
|
||||||
encode(self.uid.as_ref()).to_string()
|
|
||||||
);
|
|
||||||
if let Some(limit) = options.limit {
|
if let Some(limit) = options.limit {
|
||||||
url.push_str(&format!("limit={}&", limit));
|
url.push_str(&format!("limit={}&", limit));
|
||||||
}
|
}
|
||||||
@ -177,26 +161,19 @@ impl Index<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_document(&self, id: u64) -> (Value, StatusCode) {
|
pub async fn delete_document(&self, id: u64) -> (Value, StatusCode) {
|
||||||
let url = format!(
|
let url = format!("/indexes/{}/documents/{}", encode(self.uid.as_ref()), id);
|
||||||
"/indexes/{}/documents/{}",
|
|
||||||
encode(self.uid.as_ref()).to_string(),
|
|
||||||
id
|
|
||||||
);
|
|
||||||
self.service.delete(url).await
|
self.service.delete(url).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn clear_all_documents(&self) -> (Value, StatusCode) {
|
pub async fn clear_all_documents(&self) -> (Value, StatusCode) {
|
||||||
let url = format!(
|
let url = format!("/indexes/{}/documents", encode(self.uid.as_ref()));
|
||||||
"/indexes/{}/documents",
|
|
||||||
encode(self.uid.as_ref()).to_string()
|
|
||||||
);
|
|
||||||
self.service.delete(url).await
|
self.service.delete(url).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_batch(&self, ids: Vec<u64>) -> (Value, StatusCode) {
|
pub async fn delete_batch(&self, ids: Vec<u64>) -> (Value, StatusCode) {
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"/indexes/{}/documents/delete-batch",
|
"/indexes/{}/documents/delete-batch",
|
||||||
encode(self.uid.as_ref()).to_string()
|
encode(self.uid.as_ref())
|
||||||
);
|
);
|
||||||
self.service
|
self.service
|
||||||
.post(url, serde_json::to_value(&ids).unwrap())
|
.post(url, serde_json::to_value(&ids).unwrap())
|
||||||
@ -204,31 +181,22 @@ impl Index<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn settings(&self) -> (Value, StatusCode) {
|
pub async fn settings(&self) -> (Value, StatusCode) {
|
||||||
let url = format!(
|
let url = format!("/indexes/{}/settings", encode(self.uid.as_ref()));
|
||||||
"/indexes/{}/settings",
|
|
||||||
encode(self.uid.as_ref()).to_string()
|
|
||||||
);
|
|
||||||
self.service.get(url).await
|
self.service.get(url).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_settings(&self, settings: Value) -> (Value, StatusCode) {
|
pub async fn update_settings(&self, settings: Value) -> (Value, StatusCode) {
|
||||||
let url = format!(
|
let url = format!("/indexes/{}/settings", encode(self.uid.as_ref()));
|
||||||
"/indexes/{}/settings",
|
|
||||||
encode(self.uid.as_ref()).to_string()
|
|
||||||
);
|
|
||||||
self.service.post(url, settings).await
|
self.service.post(url, settings).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_settings(&self) -> (Value, StatusCode) {
|
pub async fn delete_settings(&self) -> (Value, StatusCode) {
|
||||||
let url = format!(
|
let url = format!("/indexes/{}/settings", encode(self.uid.as_ref()));
|
||||||
"/indexes/{}/settings",
|
|
||||||
encode(self.uid.as_ref()).to_string()
|
|
||||||
);
|
|
||||||
self.service.delete(url).await
|
self.service.delete(url).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn stats(&self) -> (Value, StatusCode) {
|
pub async fn stats(&self) -> (Value, StatusCode) {
|
||||||
let url = format!("/indexes/{}/stats", encode(self.uid.as_ref()).to_string());
|
let url = format!("/indexes/{}/stats", encode(self.uid.as_ref()));
|
||||||
self.service.get(url).await
|
self.service.get(url).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,17 +221,13 @@ impl Index<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn search_post(&self, query: Value) -> (Value, StatusCode) {
|
pub async fn search_post(&self, query: Value) -> (Value, StatusCode) {
|
||||||
let url = format!("/indexes/{}/search", encode(self.uid.as_ref()).to_string());
|
let url = format!("/indexes/{}/search", encode(self.uid.as_ref()));
|
||||||
self.service.post(url, query).await
|
self.service.post(url, query).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn search_get(&self, query: Value) -> (Value, StatusCode) {
|
pub async fn search_get(&self, query: Value) -> (Value, StatusCode) {
|
||||||
let params = serde_url_params::to_string(&query).unwrap();
|
let params = serde_url_params::to_string(&query).unwrap();
|
||||||
let url = format!(
|
let url = format!("/indexes/{}/search?{}", encode(self.uid.as_ref()), params);
|
||||||
"/indexes/{}/search?{}",
|
|
||||||
encode(self.uid.as_ref()).to_string(),
|
|
||||||
params
|
|
||||||
);
|
|
||||||
self.service.get(url).await
|
self.service.get(url).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ pub fn default_settings(dir: impl AsRef<Path>) -> Opt {
|
|||||||
master_key: None,
|
master_key: None,
|
||||||
env: "development".to_owned(),
|
env: "development".to_owned(),
|
||||||
#[cfg(all(not(debug_assertions), feature = "analytics"))]
|
#[cfg(all(not(debug_assertions), feature = "analytics"))]
|
||||||
no_analytics: Some(Some(true)),
|
no_analytics: true,
|
||||||
max_index_size: Byte::from_unit(4.0, ByteUnit::GiB).unwrap(),
|
max_index_size: Byte::from_unit(4.0, ByteUnit::GiB).unwrap(),
|
||||||
max_task_db_size: Byte::from_unit(4.0, ByteUnit::GiB).unwrap(),
|
max_task_db_size: Byte::from_unit(4.0, ByteUnit::GiB).unwrap(),
|
||||||
http_payload_size_limit: Byte::from_unit(10.0, ByteUnit::MiB).unwrap(),
|
http_payload_size_limit: Byte::from_unit(10.0, ByteUnit::MiB).unwrap(),
|
||||||
|
@ -28,9 +28,7 @@ impl Index {
|
|||||||
pub fn dump(&self, path: impl AsRef<Path>) -> Result<()> {
|
pub fn dump(&self, path: impl AsRef<Path>) -> Result<()> {
|
||||||
// acquire write txn make sure any ongoing write is finished before we start.
|
// acquire write txn make sure any ongoing write is finished before we start.
|
||||||
let txn = self.env.write_txn()?;
|
let txn = self.env.write_txn()?;
|
||||||
let path = path
|
let path = path.as_ref().join(format!("indexes/{}", self.uuid));
|
||||||
.as_ref()
|
|
||||||
.join(format!("indexes/{}", self.uuid.to_string()));
|
|
||||||
|
|
||||||
create_dir_all(&path)?;
|
create_dir_all(&path)?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user