Skip to content

Commit 5c3cda9

Browse files
squadgazzzxdecentralix
authored andcommitted
[EASY] Drop auction_orders table (cowprotocol#3747)
# Description Drops the `auction_orders` table, which contains duplicated data in the `competition_auctions` table. The same data is used there: https://github.com/cowprotocol/services/blob/979e924dae38ba18bf398447e399092867edaf3f/crates/autopilot/src/infra/persistence/mod.rs#L302-L306 ## How to test Existing tests. No usages apart from this repo: https://github.com/search?q=org%3Acowprotocol+auction_orders+-repo%3Acowprotocol%2Fservices&type=code The following query returns 0, which should tell how many `auction_orders.auction_id` do not exist in `competition_auctions.id`. ```sql SELECT COUNT(*) FROM auction_orders ao WHERE NOT EXISTS ( SELECT 1 FROM competition_auctions ca WHERE ca.id = ao.auction_id ); ```
1 parent 6f6df62 commit 5c3cda9

File tree

7 files changed

+19
-85
lines changed

7 files changed

+19
-85
lines changed

crates/autopilot/src/database/competition.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ impl super::Postgres {
3939
.with_label_values(&["save_competition"])
4040
.start_timer();
4141

42-
let competition_orders = competition
43-
.competition_table
44-
.auction
45-
.orders
46-
.iter()
47-
.map(|order| ByteArray(order.0))
48-
.collect::<Vec<_>>();
49-
5042
// offload CPU intensive work of serializing to a blocking thread so we can
5143
// already start with the DB queries in the mean time.
5244
let json = tokio::task::spawn_blocking(move || {
@@ -100,10 +92,6 @@ impl super::Postgres {
10092
.await
10193
.context("auction_prices::insert")?;
10294

103-
database::auction_orders::insert(&mut ex, competition.auction_id, &competition_orders)
104-
.await
105-
.context("auction_orders::insert")?;
106-
10795
let json = json
10896
.await
10997
.context("failed to await blocking task")?

crates/autopilot/src/infra/persistence/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl Persistence {
367367

368368
let orders = {
369369
// get all orders from a competition auction
370-
let auction_orders = database::auction_orders::fetch(&mut ex, auction_id)
370+
let auction_orders = database::auction::get_order_uids(&mut ex, auction_id)
371371
.await
372372
.map_err(error::Auction::DatabaseError)?
373373
.ok_or(error::Auction::NotFound)?

crates/database/src/auction.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ pub async fn fetch(ex: &mut PgConnection, id: AuctionId) -> Result<Option<Auctio
7272
sqlx::query_as(QUERY).bind(id).fetch_optional(ex).await
7373
}
7474

75+
pub async fn get_order_uids(
76+
ex: &mut PgConnection,
77+
auction_id: AuctionId,
78+
) -> Result<Option<Vec<OrderUid>>, sqlx::Error> {
79+
const QUERY: &str = r#"SELECT order_uids FROM competition_auctions WHERE id = $1;"#;
80+
let record: Option<(Vec<OrderUid>,)> = sqlx::query_as(QUERY)
81+
.bind(auction_id)
82+
.fetch_optional(ex)
83+
.await?;
84+
Ok(record.map(|(order_uids,)| order_uids))
85+
}
86+
7587
#[cfg(test)]
7688
mod tests {
7789
use {super::*, crate::byte_array::ByteArray, sqlx::Connection};
@@ -102,13 +114,16 @@ mod tests {
102114
id: id_,
103115
block: 1,
104116
deadline: 2,
105-
order_uids: vec![ByteArray([1u8; 56])],
117+
order_uids: vec![ByteArray([1u8; 56]), ByteArray([2u8; 56])],
106118
price_tokens: vec![ByteArray([1u8; 20])],
107119
price_values: vec![BigDecimal::from(1)],
108120
surplus_capturing_jit_order_owners: vec![ByteArray([1u8; 20])],
109121
};
110122
save(&mut db, auction.clone()).await.unwrap();
111123
let auction_ = fetch(&mut db, id_).await.unwrap().unwrap();
112124
assert_eq!(auction, auction_);
125+
126+
let order_uids = get_order_uids(&mut db, id_).await.unwrap().unwrap();
127+
assert_eq!(auction.order_uids, order_uids);
113128
}
114129
}

crates/database/src/auction_orders.rs

Lines changed: 0 additions & 57 deletions
This file was deleted.

crates/database/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pub mod app_data;
22
pub mod auction;
3-
pub mod auction_orders;
43
pub mod auction_participants;
54
pub mod auction_prices;
65
pub mod byte_array;
@@ -53,7 +52,6 @@ pub type PgTransaction<'a> = sqlx::Transaction<'a, sqlx::Postgres>;
5352
/// The names of tables we use in the db.
5453
pub const TABLES: &[&str] = &[
5554
"app_data",
56-
"auction_orders",
5755
"auctions",
5856
"ethflow_orders",
5957
"ethflow_refunds",

database/README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -482,18 +482,6 @@ Indexes:
482482
- PRIMARY KEY: btree(`block_number`, `log_index`)
483483
- trade\_order\_uid: btree (`order_uid`, `block_number`, `log_index`)
484484

485-
### auction\_orders
486-
487-
Stores all orders that were included in a given auction. The same order can be included in multiple auctions.
488-
489-
Column | Type | Nullable | Details
490-
------------|---------|----------|--------
491-
auction\_id | bigint | not null | which auction this order was part of
492-
order\_uids | bytea[] | not null | order uids that were included in the auction
493-
494-
Indexes:
495-
- PRIMARY KEY: btree(`auction_uid`)
496-
497485
### surplus\_capturing\_jit\_order\_owners
498486

499487
Stores all surplus capturing jit order owners that are part of an auction. JIT orders settled for addresses which were not part of a given auction will not count towards surplus.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Drop auction_orders table
2+
DROP TABLE IF EXISTS auction_orders;

0 commit comments

Comments
 (0)