This commit is contained in:
JMARyA 2024-08-28 09:38:10 +02:00
parent 92e2da9cae
commit acf5ebae78
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
6 changed files with 56 additions and 47 deletions

View file

@ -1,3 +1,5 @@
use mongod::Model;
use crate::item::Item;
/// Item database
@ -15,6 +17,7 @@ impl ItemDB {
for item in &index.documents {
let item = Item::new(item);
item.insert_overwrite().await.unwrap();
log::info!("Adding item {} to DB", item.name);
}
@ -23,13 +26,11 @@ impl ItemDB {
/// Retrieves an item by name
pub fn get_item(&self, item: &str) -> Option<Item> {
Some(
self.index
.documents
.iter()
.map(Item::new) // <-- todo : performance?
.find(|x| x.name == item)?,
)
self.index
.documents
.iter()
.map(Item::new) // <-- todo : performance?
.find(|x| x.name == item)
}
/// Get all items