rename a few things for consistency

This commit is contained in:
Tamo 2022-10-06 16:37:13 +02:00 committed by Clément Renault
parent a8128678a4
commit 2f47443458
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
5 changed files with 83 additions and 40 deletions

View File

@ -2,6 +2,7 @@
// pub mod v3;
// pub mod v4;
// pub mod v4_to_v5;
pub mod v5_to_v6;
pub struct Compat<From: ?Sized> {

View File

@ -1,5 +1,3 @@
use std::fs::File;
use crate::reader::{v5, v6, DumpReader, IndexReader};
use crate::Result;
@ -44,52 +42,52 @@ impl DumpReader for CompatV5ToV6 {
) -> Box<dyn Iterator<Item = Result<(v6::Task, Option<v6::UpdateFile>)>> + '_> {
Box::new(self.from.tasks().map(|task| {
task.map(|(task, content_file)| {
let task_view: v5::TaskView = task.into();
let task_view: v5::tasks::TaskView = task.into();
let task = v6::Task {
uid: task_view.uid,
index_uid: task_view.index_uid,
status: match task_view.status {
v5::TaskStatus::Enqueued => v6::Status::Enqueued,
v5::TaskStatus::Processing => v6::Status::Enqueued,
v5::TaskStatus::Succeeded => v6::Status::Succeeded,
v5::TaskStatus::Failed => v6::Status::Failed,
v5::Status::Enqueued => v6::Status::Enqueued,
v5::Status::Processing => v6::Status::Enqueued,
v5::Status::Succeeded => v6::Status::Succeeded,
v5::Status::Failed => v6::Status::Failed,
},
kind: match task_view.task_type {
v5::TaskType::IndexCreation => v6::Kind::IndexCreation,
v5::TaskType::IndexUpdate => v6::Kind::IndexUpdate,
v5::TaskType::IndexDeletion => v6::Kind::IndexDeletion,
v5::Kind::IndexCreation => v6::Kind::IndexCreation,
v5::Kind::IndexUpdate => v6::Kind::IndexUpdate,
v5::Kind::IndexDeletion => v6::Kind::IndexDeletion,
// TODO: this is a `DocumentAdditionOrUpdate` but we still don't have this type in the `TaskView`.
v5::TaskType::DocumentAdditionOrUpdate => v6::Kind::DocumentAddition,
v5::TaskType::DocumentDeletion => v6::Kind::DocumentDeletion,
v5::TaskType::SettingsUpdate => v6::Kind::Settings,
v5::TaskType::DumpCreation => v6::Kind::DumpExport,
v5::Kind::DocumentAdditionOrUpdate => v6::Kind::DocumentAddition,
v5::Kind::DocumentDeletion => v6::Kind::DocumentDeletion,
v5::Kind::SettingsUpdate => v6::Kind::Settings,
v5::Kind::DumpCreation => v6::Kind::DumpExport,
},
details: task_view.details.map(|details| match details {
v5::TaskDetails::DocumentAddition {
v5::Details::DocumentAddition {
received_documents,
indexed_documents,
} => v6::Details::DocumentAddition {
received_documents: received_documents as u64,
indexed_documents: indexed_documents.map_or(0, |i| i as u64),
},
v5::TaskDetails::Settings { settings } => v6::Details::Settings {
v5::Details::Settings { settings } => v6::Details::Settings {
settings: settings.into(),
},
v5::TaskDetails::IndexInfo { primary_key } => {
v5::Details::IndexInfo { primary_key } => {
v6::Details::IndexInfo { primary_key }
}
v5::TaskDetails::DocumentDeletion {
v5::Details::DocumentDeletion {
received_document_ids,
deleted_documents,
} => v6::Details::DocumentDeletion {
received_document_ids,
deleted_documents,
},
v5::TaskDetails::ClearAll { deleted_documents } => {
v5::Details::ClearAll { deleted_documents } => {
v6::Details::ClearAll { deleted_documents }
}
v5::TaskDetails::Dump { dump_uid } => v6::Details::Dump { dump_uid },
v5::Details::Dump { dump_uid } => v6::Details::Dump { dump_uid },
}),
error: task_view.error.map(|e| e.into()),
duration: task_view.duration,

View File

@ -16,17 +16,38 @@ mod tasks;
use crate::{IndexMetadata, Result, Version};
use self::{
keys::Key,
meta::{DumpMeta, IndexUuid},
settings::{Checked, Settings},
tasks::Task,
};
use self::meta::{DumpMeta, IndexUuid};
use super::{/* compat::v4_to_v5::CompatV4ToV5, */ DumpReader, IndexReader};
pub type Document = serde_json::Map<String, serde_json::Value>;
pub type Settings<T> = settings::Settings<T>;
pub type Checked = settings::Checked;
pub type Unchecked = settings::Unchecked;
pub type Task = tasks::Task;
pub type UpdateFile = File;
pub type Key = keys::Key;
// ===== Other types to clarify the code of the compat module
// everything related to the tasks
pub type Status = tasks::TaskStatus;
pub type Kind = tasks::TaskType;
pub type Details = tasks::TaskDetails;
// everything related to the settings
pub type Setting<T> = settings::Setting<T>;
pub type TypoTolerance = settings::TypoSettings;
pub type MinWordSizeForTypos = settings::MinWordSizeTyposSetting;
// everything related to the api keys
pub type Action = keys::Action;
pub type StarOr<T> = meta::StarOr<T>;
pub type IndexUid = meta::IndexUid;
// everything related to the errors
pub type ResponseError = tasks::ResponseError;
pub type Code = meilisearch_types::error::Code;
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]

View File

@ -52,7 +52,7 @@ pub enum TaskContent {
#[cfg_attr(test, derive(serde::Serialize))]
#[cfg_attr(test, serde(untagged))]
#[allow(clippy::large_enum_variant)]
enum TaskDetails {
pub enum TaskDetails {
#[cfg_attr(test, serde(rename_all = "camelCase"))]
DocumentAddition {
received_documents: usize,
@ -77,7 +77,7 @@ enum TaskDetails {
#[derive(Debug)]
#[cfg_attr(test, derive(serde::Serialize))]
#[cfg_attr(test, serde(rename_all = "camelCase"))]
enum TaskStatus {
pub enum TaskStatus {
Enqueued,
Processing,
Succeeded,
@ -87,7 +87,7 @@ enum TaskStatus {
#[derive(Debug)]
#[cfg_attr(test, derive(serde::Serialize))]
#[cfg_attr(test, serde(rename_all = "camelCase"))]
enum TaskType {
pub enum TaskType {
IndexCreation,
IndexUpdate,
IndexDeletion,

View File

@ -47,18 +47,41 @@ use crate::{IndexMetadata, Result, Version};
use super::{compat::v5_to_v6::CompatV5ToV6, DumpReader, IndexReader};
mod keys;
mod meta;
mod settings;
mod tasks;
pub use keys::*;
pub use meta::*;
pub use settings::*;
pub use tasks::*;
pub mod keys;
pub mod meta;
pub mod settings;
pub mod tasks;
pub type Document = serde_json::Map<String, serde_json::Value>;
pub type Settings<T> = settings::Settings<T>;
pub type Checked = settings::Checked;
pub type Unchecked = settings::Unchecked;
pub type Task = tasks::Task;
pub type UpdateFile = File;
pub type Key = keys::Key;
// ===== Other types to clarify the code of the compat module
// everything related to the tasks
pub type Status = tasks::TaskStatus;
pub type Kind = tasks::TaskType;
pub type Details = tasks::TaskDetails;
// everything related to the settings
pub type Setting<T> = settings::Setting<T>;
pub type TypoTolerance = settings::TypoSettings;
pub type MinWordSizeForTypos = settings::MinWordSizeTyposSetting;
pub type FacetingSettings = settings::FacetingSettings;
pub type PaginationSettings = settings::PaginationSettings;
// everything related to the api keys
pub type Action = keys::Action;
pub type StarOr<T> = meta::StarOr<T>;
pub type IndexUid = meta::IndexUid;
// everything related to the errors
pub type ResponseError = tasks::ResponseError;
pub type Code = meilisearch_types::error::Code;
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
@ -75,7 +98,7 @@ pub struct V5Reader {
metadata: Metadata,
tasks: BufReader<File>,
keys: BufReader<File>,
index_uuid: Vec<IndexUuid>,
index_uuid: Vec<meta::IndexUuid>,
}
impl V5Reader {
@ -168,7 +191,7 @@ pub struct V5IndexReader {
impl V5IndexReader {
pub fn new(name: String, path: &Path) -> Result<Self> {
let meta = File::open(path.join("meta.json"))?;
let meta: DumpMeta = serde_json::from_reader(meta)?;
let meta: meta::DumpMeta = serde_json::from_reader(meta)?;
let metadata = IndexMetadata {
uid: name,