| 91 | |
| 92 | #[instrument(skip_all)] |
| 93 | async fn insert_invalidation( |
| 94 | ex: &mut PgConnection, |
| 95 | index: &EventIndex, |
| 96 | event: &Invalidation, |
| 97 | ) -> Result<(), sqlx::Error> { |
| 98 | // We use ON CONFLICT so that multiple updates running at the same do not error |
| 99 | // because of events already existing. This can happen when multiple |
| 100 | // orderbook apis run in HPA. See #444 . |
| 101 | const QUERY: &str = "INSERT INTO invalidations (block_number, log_index, order_uid) VALUES \ |
| 102 | ($1, $2, $3) ON CONFLICT DO NOTHING;"; |
| 103 | sqlx::query(QUERY) |
| 104 | .bind(index.block_number) |
| 105 | .bind(index.log_index) |
| 106 | .bind(event.order_uid) |
| 107 | .execute(ex) |
| 108 | .await?; |
| 109 | Ok(()) |
| 110 | } |
| 111 | |
| 112 | #[instrument(skip_all)] |
| 113 | pub async fn insert_trade( |