add sharding recipe, filtered by category
This commit is contained in:
parent
2cd66711d6
commit
c8351d108c
1 changed files with 41 additions and 9 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::Read;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
|
@ -15,7 +15,7 @@ pub struct RecipeListChange {
|
|||
pub raw_old: Vec<crate::models::recipe::RecipeList>,
|
||||
pub raw_new: Vec<crate::models::recipe::RecipeList>,
|
||||
/// for sub menu
|
||||
pub sub_changes: HashMap<String, Value>,
|
||||
pub sub_changes: BTreeMap<String, Value>,
|
||||
}
|
||||
|
||||
impl RecipeListChange {
|
||||
|
|
@ -73,9 +73,41 @@ impl RecipeListChange {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ShardingRecipe {
|
||||
pub category_map: BTreeMap<String, Value>,
|
||||
}
|
||||
|
||||
impl ShardingRecipe {
|
||||
pub fn build(data: BTreeMap<String, Value>) -> Self {
|
||||
let keylist: Vec<String> = data.keys().map(|k| k.to_string()).collect();
|
||||
let mut category_map = BTreeMap::new();
|
||||
|
||||
for key in keylist {
|
||||
let kspl: Vec<&str> = key.split("-").collect();
|
||||
|
||||
if kspl.len() > 3 {
|
||||
let category = kspl[1].to_string();
|
||||
|
||||
if !category_map.contains_key(&category.clone()) {
|
||||
category_map.insert(category.clone(), serde_json::json!(Vec::<Value>::new()));
|
||||
}
|
||||
|
||||
category_map
|
||||
.get_mut(&category.clone())
|
||||
.unwrap()
|
||||
.as_array_mut()
|
||||
.unwrap()
|
||||
.push(serde_json::to_value(data.get(&key).unwrap()).unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
Self { category_map }
|
||||
}
|
||||
}
|
||||
|
||||
/// break down recipe(s) in the folder into mapping,
|
||||
/// tracking diff between fields. (This does not compare other fields than Recipe01)
|
||||
pub fn build_recipe_shardings(source: PathBuf) -> HashMap<String, Value> {
|
||||
pub fn build_recipe_shardings(source: PathBuf) -> ShardingRecipe {
|
||||
let files = common::get_all_files_in_directory(source.as_path().to_str().unwrap());
|
||||
let known_latest_version = format!("{}/version", source.as_path().to_str().unwrap());
|
||||
let mut latest_version_string = String::new();
|
||||
|
|
@ -102,7 +134,7 @@ pub fn build_recipe_shardings(source: PathBuf) -> HashMap<String, Value> {
|
|||
|
||||
// Structure
|
||||
// { productCode: { version: [ Option<RecipeChange> ] } }
|
||||
let mut shards = HashMap::new();
|
||||
let mut shards = BTreeMap::new();
|
||||
|
||||
if recipes.is_empty() {
|
||||
eprintln!("recipes get empty!!!");
|
||||
|
|
@ -129,7 +161,7 @@ pub fn build_recipe_shardings(source: PathBuf) -> HashMap<String, Value> {
|
|||
.Recipe01
|
||||
.par_iter()
|
||||
.map(|rp1| {
|
||||
let mut sub_changes = HashMap::new();
|
||||
let mut sub_changes = BTreeMap::new();
|
||||
|
||||
if rp1.clone().SubMenu.is_some() {
|
||||
let subs = rp1.clone().SubMenu.unwrap().clone();
|
||||
|
|
@ -141,10 +173,10 @@ pub fn build_recipe_shardings(source: PathBuf) -> HashMap<String, Value> {
|
|||
new_value: Value::Null,
|
||||
raw_new: sub1.recipes.clone(),
|
||||
raw_old: sub1.recipes.clone(),
|
||||
sub_changes: HashMap::new(),
|
||||
sub_changes: BTreeMap::new(),
|
||||
};
|
||||
|
||||
let mut change_sub_map = HashMap::new();
|
||||
let mut change_sub_map = BTreeMap::new();
|
||||
change_sub_map.insert(base_version, change_sub.clone());
|
||||
recipes.iter().for_each(|rc| {
|
||||
// clone change
|
||||
|
|
@ -182,7 +214,7 @@ pub fn build_recipe_shardings(source: PathBuf) -> HashMap<String, Value> {
|
|||
sub_changes,
|
||||
};
|
||||
|
||||
let mut change_map = HashMap::new();
|
||||
let mut change_map = BTreeMap::new();
|
||||
change_map.insert(base_version, change.clone());
|
||||
recipes.iter().for_each(|rc| {
|
||||
// clone change
|
||||
|
|
@ -212,5 +244,5 @@ pub fn build_recipe_shardings(source: PathBuf) -> HashMap<String, Value> {
|
|||
})
|
||||
.collect();
|
||||
|
||||
shards
|
||||
ShardingRecipe::build(shards)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue