Apply all the deletes and inserts recorded in `diff`. Return a [`TableAppliedDiff`] which encodes the actual changes to rows present or deleted after taking into account rows' refcounts. The resulting [`TableAppliedDiff`] will contain only deletes and inserts. Its `update_deletes` and `update_inserts` fields will be empty. The caller should use [`TableAppliedDiff::with_updates_by_pk`] to merge de
(&mut self, diff: &'r TableUpdate<Row>)
| 267 | /// The caller should use [`TableAppliedDiff::with_updates_by_pk`] to merge delete/insert pairs |
| 268 | /// and populate the `update_*` fields. |
| 269 | fn apply_diff<'r>(&mut self, diff: &'r TableUpdate<Row>) -> TableAppliedDiff<'r, Row> { |
| 270 | // Apply all inserts and collect all `ref_count: 0 -> 1` events. |
| 271 | // Inserts must be applied before deletes to avoid the panic in `handle_delete` |
| 272 | // and to avoid duplicate index insertion errors. |
| 273 | let mut insert_events = <_>::default(); |
| 274 | for insert in &diff.inserts { |
| 275 | self.handle_insert(&mut insert_events, insert); |
| 276 | } |
| 277 | |
| 278 | // Apply all deletes and collect all `ref_count -> 0` events. |
| 279 | let mut delete_events = <_>::default(); |
| 280 | for delete in &diff.deletes { |
| 281 | self.handle_delete(&mut insert_events, &mut delete_events, delete); |
| 282 | } |
| 283 | |
| 284 | // Update indices. |
| 285 | // We apply deletes first to make space for later insertions |
| 286 | // and to avoid duplicates in any unique index. |
| 287 | for index in self.unique_indices.values_mut() { |
| 288 | for row in delete_events.values() { |
| 289 | index.remove_row(row); |
| 290 | } |
| 291 | for &row in insert_events.values() { |
| 292 | index.add_row(row.clone()); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | TableAppliedDiff { |
| 297 | deletes: delete_events, |
| 298 | inserts: insert_events, |
| 299 | update_deletes: Vec::new(), |
| 300 | update_inserts: Vec::new(), |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | fn find_by_unique_index<'this>( |
| 305 | &'this self, |
no test coverage detected