mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 04:17:10 +02:00
Fix most of the easy issues
This commit is contained in:
parent
7219299436
commit
85037352b9
6 changed files with 39 additions and 16 deletions
|
@ -178,8 +178,8 @@ make_enum_progress! {
|
||||||
make_enum_progress! {
|
make_enum_progress! {
|
||||||
pub enum Export {
|
pub enum Export {
|
||||||
EnsuringCorrectnessOfTheTarget,
|
EnsuringCorrectnessOfTheTarget,
|
||||||
ExportTheSettings,
|
ExporingTheSettings,
|
||||||
ExportTheDocuments,
|
ExporingTheDocuments,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -510,9 +510,9 @@ impl IndexScheduler {
|
||||||
// 3. we batch the export.
|
// 3. we batch the export.
|
||||||
let to_export = self.queue.tasks.get_kind(rtxn, Kind::Export)? & enqueued;
|
let to_export = self.queue.tasks.get_kind(rtxn, Kind::Export)? & enqueued;
|
||||||
if !to_export.is_empty() {
|
if !to_export.is_empty() {
|
||||||
let mut tasks = self.queue.tasks.get_existing_tasks(rtxn, to_export)?;
|
let task_id = to_export.iter().next().expect("There must be only one export task");
|
||||||
current_batch.processing(&mut tasks);
|
let mut task = self.queue.tasks.get_task(rtxn, task_id)?.unwrap();
|
||||||
let task = tasks.pop().expect("There must be only one export task");
|
current_batch.processing([&mut task]);
|
||||||
current_batch.reason(BatchStopReason::TaskKindCannotBeBatched { kind: Kind::Export });
|
current_batch.reason(BatchStopReason::TaskKindCannotBeBatched { kind: Kind::Export });
|
||||||
return Ok(Some((Batch::Export { task }, current_batch)));
|
return Ok(Some((Batch::Export { task }, current_batch)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,10 +86,11 @@ impl IndexScheduler {
|
||||||
}
|
}
|
||||||
// Retry logic for sending settings
|
// Retry logic for sending settings
|
||||||
let url = format!("{base_url}/indexes/{uid}/settings");
|
let url = format!("{base_url}/indexes/{uid}/settings");
|
||||||
|
let bearer = api_key.map(|api_key| format!("Bearer {api_key}"));
|
||||||
retry(&must_stop_processing, || {
|
retry(&must_stop_processing, || {
|
||||||
let mut request = agent.patch(&url);
|
let mut request = agent.patch(&url);
|
||||||
if let Some(api_key) = api_key {
|
if let Some(bearer) = bearer.as_ref() {
|
||||||
request = request.set("Authorization", &format!("Bearer {api_key}"));
|
request = request.set("Authorization", bearer);
|
||||||
}
|
}
|
||||||
request.send_json(settings.clone()).map_err(into_backoff_error)
|
request.send_json(settings.clone()).map_err(into_backoff_error)
|
||||||
})?;
|
})?;
|
||||||
|
|
|
@ -273,7 +273,7 @@ pub fn swap_index_uid_in_task(task: &mut Task, swap: (&str, &str)) {
|
||||||
K::TaskCancelation { .. }
|
K::TaskCancelation { .. }
|
||||||
| K::TaskDeletion { .. }
|
| K::TaskDeletion { .. }
|
||||||
| K::DumpCreation { .. }
|
| K::DumpCreation { .. }
|
||||||
| K::Export { .. } // TODO I have patterns, not index uids
|
| K::Export { .. }
|
||||||
| K::UpgradeDatabase { .. }
|
| K::UpgradeDatabase { .. }
|
||||||
| K::SnapshotCreation => (),
|
| K::SnapshotCreation => (),
|
||||||
};
|
};
|
||||||
|
|
|
@ -371,7 +371,10 @@ impl From<Details> for DetailsView {
|
||||||
}
|
}
|
||||||
Details::Export { url, api_key, payload_size, indexes } => DetailsView {
|
Details::Export { url, api_key, payload_size, indexes } => DetailsView {
|
||||||
url: Some(url),
|
url: Some(url),
|
||||||
api_key,
|
api_key: api_key.map(|mut api_key| {
|
||||||
|
hide_secret(&mut api_key);
|
||||||
|
api_key
|
||||||
|
}),
|
||||||
payload_size: payload_size
|
payload_size: payload_size
|
||||||
.map(|ps| ps.get_appropriate_unit(UnitType::Both).to_string()),
|
.map(|ps| ps.get_appropriate_unit(UnitType::Both).to_string()),
|
||||||
indexes: Some(
|
indexes: Some(
|
||||||
|
@ -390,3 +393,21 @@ impl From<Details> for DetailsView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We definitely need to factorize the code to hide the secret key
|
||||||
|
fn hide_secret(secret: &mut String) {
|
||||||
|
match secret.len() {
|
||||||
|
x if x < 10 => {
|
||||||
|
secret.replace_range(.., "XXX...");
|
||||||
|
}
|
||||||
|
x if x < 20 => {
|
||||||
|
secret.replace_range(2.., "XXXX...");
|
||||||
|
}
|
||||||
|
x if x < 30 => {
|
||||||
|
secret.replace_range(3.., "XXXXX...");
|
||||||
|
}
|
||||||
|
_x => {
|
||||||
|
secret.replace_range(5.., "XXXXXX...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -42,16 +42,17 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
get,
|
post,
|
||||||
path = "",
|
path = "",
|
||||||
tag = "Export",
|
tag = "Export",
|
||||||
security(("Bearer" = ["export", "*"])),
|
security(("Bearer" = ["export", "*"])),
|
||||||
responses(
|
responses(
|
||||||
(status = OK, description = "Known nodes are returned", body = Export, content_type = "application/json", example = json!(
|
(status = OK, description = "Known nodes are returned", body = Export, content_type = "application/json", example = json!(
|
||||||
{
|
{
|
||||||
"indexes": ["movie", "steam-*"],
|
"taskUid": 1,
|
||||||
"skip_embeddings": true,
|
"status": "enqueued",
|
||||||
"apiKey": "meilisearch-api-key"
|
"type": "export",
|
||||||
|
"enqueuedAt": "2021-08-11T09:25:53.000000Z"
|
||||||
})),
|
})),
|
||||||
(status = 401, description = "The authorization header is missing", body = ResponseError, content_type = "application/json", example = json!(
|
(status = 401, description = "The authorization header is missing", body = ResponseError, content_type = "application/json", example = json!(
|
||||||
{
|
{
|
||||||
|
@ -126,7 +127,7 @@ pub struct Export {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidExportPayloadSize>)]
|
#[deserr(default, error = DeserrJsonError<InvalidExportPayloadSize>)]
|
||||||
pub payload_size: Option<ByteWithDeserr>,
|
pub payload_size: Option<ByteWithDeserr>,
|
||||||
#[schema(value_type = Option<BTreeSet<String>>, example = json!(["movies", "steam-*"]))]
|
#[schema(value_type = Option<BTreeMap<String, ExportIndexSettings>>, example = json!({ "*": { "filter": null } }))]
|
||||||
#[deserr(default)]
|
#[deserr(default)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub indexes: BTreeMap<IndexUidPattern, ExportIndexSettings>,
|
pub indexes: BTreeMap<IndexUidPattern, ExportIndexSettings>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue