refactor
This commit is contained in:
parent
92e2da9cae
commit
acf5ebae78
6 changed files with 56 additions and 47 deletions
15
src/db.rs
15
src/db.rs
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue