(
db: &Database,
events: impl Iterator<Item = event::ActiveModel>,
)
| 134 | } |
| 135 | |
| 136 | pub async fn insert_events( |
| 137 | db: &Database, |
| 138 | events: impl Iterator<Item = event::ActiveModel>, |
| 139 | ) -> Result<(), DbErr> { |
| 140 | let db = db.db(); |
| 141 | let mut hits: HashMap<u32, usize> = Default::default(); |
| 142 | let mut functions: HashSet<String> = Default::default(); |
| 143 | let events: Vec<_> = events.collect(); |
| 144 | for event in events.iter() { |
| 145 | if let Some(function_name) = event.function_name.as_ref() { |
| 146 | functions.insert(function_name.clone()); |
| 147 | } |
| 148 | let bp_id = event.breakpoint_id.as_ref(); |
| 149 | let hit = hits.entry(*bp_id).or_default(); |
| 150 | *hit += 1; |
| 151 | } |
| 152 | |
| 153 | let start = std::time::Instant::now(); |
| 154 | let res = Event::insert_many(events) |
| 155 | .on_empty_do_nothing() |
| 156 | .exec(db) |
| 157 | .await?; |
| 158 | let duration = start.elapsed(); |
| 159 | log::debug!("Event::insert_many: {:?} in {:?}", res, duration); |
| 160 | |
| 161 | inc_hit_count(db, hits).await?; |
| 162 | insert_functions(db, functions).await?; |
| 163 | |
| 164 | Ok(()) |
| 165 | } |
| 166 | |
| 167 | async fn inc_hit_count(db: &DbConn, breakpoints: HashMap<u32, usize>) -> Result<(), DbErr> { |
| 168 | // we batch the updates for all the breakpoints hit by N |
no test coverage detected