diff --git a/src/app.rs b/src/app.rs index 8eac209..eaafa91 100644 --- a/src/app.rs +++ b/src/app.rs @@ -19,7 +19,6 @@ use rusqlite::Connection; pub const USER_FONT: Font = Font::with_name("Noto Sans JP"); pub fn start() -> iced::Result { - println!("{}", size_of::()); info!("Welcome to JapLearn"); iced::application(ScreenState::boot, ScreenState::update, ScreenState::view) .window(window_settings()) diff --git a/src/data_provider/mod.rs b/src/data_provider/mod.rs index 874eae0..79e778a 100644 --- a/src/data_provider/mod.rs +++ b/src/data_provider/mod.rs @@ -37,22 +37,38 @@ where impl> DbLayer for SqliteDbLayer { fn write_entity(&self, entity: &T, connection: &Connection) -> MaybeError { + let time = Instant::now(); + connection .execute(Q::load(), Q::update_params(entity)) .map_err(|_| DbSaveError)?; + info!( + "Updated in {} for {:?}", + Q::name(), + time.elapsed() + ); Ok(()) } fn add_entity(&mut self, entity: &mut T, connection: &Connection) -> MaybeError { + let time = Instant::now(); + let index: u32 = connection .query_row(Q::add(), Q::insert_params(entity), |row| row.get(0)) .map_err(|_| DbSaveError)?; entity.set_id(index.into()); + info!( + "Added into {} for {:?}", + Q::name(), + time.elapsed() + ); Ok(()) } fn delete_entity(&mut self, id: Id, connection: &Connection) -> MaybeError { + let time = Instant::now(); + if !id.is_valid() { return Err(DbSaveError); } @@ -62,10 +78,17 @@ impl> DbLayer for SqliteDbLayer, connection: &Connection) -> MaybeError { + let time = Instant::now(); + let mut stmt = connection .prepare(Q::load()) .expect("Failed to prepare state query"); @@ -75,12 +98,21 @@ impl> DbLayer for SqliteDbLayer> BatchedDbLayer for SqliteDbLayer { fn delete_many_entities(&mut self, ids: &[Id], connection: &mut Connection) -> MaybeError { + let time = Instant::now(); + for chunk in ids.chunks(1000) { let stringed = chunk .iter() @@ -94,6 +126,13 @@ impl> BatchedDbLayer for SqliteDbLay ) .map_err(|_| DbSaveError)?; } + info!( + "Deleted {} from {} for {:?}", + ids.len(), + Q::name(), + time.elapsed() + ); + Ok(()) } @@ -121,7 +160,12 @@ impl> BatchedDbLayer for SqliteDbLay entities[index].set_id(id.into()); } - info!("Added {} entities for {:?}", entities.len(), time.elapsed()); + info!( + "Added {} into {} for {:?}", + entities.len(), + Q::name(), + time.elapsed() + ); Ok(()) } }