work
This commit is contained in:
parent
e50b51c829
commit
39905f53c2
5 changed files with 64 additions and 59 deletions
|
@ -1,6 +1,7 @@
|
|||
use mongodb::bson::doc;
|
||||
|
||||
use crate::{
|
||||
cache::InventoryCache,
|
||||
cdb_col, get_mongo,
|
||||
transaction::{BatchTransaction, Price, Transaction},
|
||||
};
|
||||
|
@ -16,6 +17,7 @@ pub struct Variant {
|
|||
pub item: String,
|
||||
pub variant: String,
|
||||
pub amount: u64,
|
||||
pub depends: Vec<String>,
|
||||
}
|
||||
|
||||
impl Variant {
|
||||
|
@ -29,6 +31,18 @@ impl Variant {
|
|||
.get("amount")
|
||||
.map(|x| x.as_u64().unwrap())
|
||||
.unwrap_or(1),
|
||||
depends: json
|
||||
.as_mapping()
|
||||
.unwrap()
|
||||
.get("depends")
|
||||
.map(|x| {
|
||||
x.as_sequence()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|x| x.as_str().unwrap().to_string())
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,6 +114,9 @@ impl Variant {
|
|||
.insert_one_with_session(transaction.as_doc(), None, &mut ses)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// update cache
|
||||
InventoryCache::push(&transaction.uuid, &mut ses).await;
|
||||
}
|
||||
|
||||
// batch transaction
|
||||
|
@ -118,10 +135,17 @@ impl Variant {
|
|||
batch.uuid
|
||||
};
|
||||
|
||||
// todo : transaction overlap cache -> scale
|
||||
|
||||
ses.commit_transaction().await.unwrap();
|
||||
|
||||
ret_uuid
|
||||
}
|
||||
|
||||
pub fn as_bson(&self) -> mongodb::bson::Document {
|
||||
mongodb::bson::doc! {
|
||||
"item": &self.item,
|
||||
"variant": &self.variant,
|
||||
"amount": self.amount as u32,
|
||||
"depends": &self.depends
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue