-
Notifications
You must be signed in to change notification settings - Fork 16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
At the moment, there are multiple changes mangled up here. I can already see that this will prove tricky to untangle into multiple, distinct commits.
I would suggest the following:
Make a new branch off master where you just change the SQL queries to use the with
syntax and move them into separate files without any of the improvements around sqlx::Type
etc.
Given that you already have the queries, that should be reasonably easy. On top of that, we can then introduce sqlx::Type
etc and get rid of all the serde_json
stuff!
leverage integer not null, | ||
liquidation_price text not null, | ||
creation_timestamp_seconds integer not null, | ||
creation_timestamp_nanoseconds integer not null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd rather drop the nanoseconds. What do you think @da-kami ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomaseizinger @da-kami I've left the ns in for the moment as they are now handled without issue. Can drop them, but it looks like that may lead to a bit more work upstream as the timestamps are generated by SystemTime::new()
so if the ns are dropped, things may not line up.
Not a big deal either way, this just seemed the path of least resistance for the moment.
daemon/src/db.rs
Outdated
@@ -296,8 +306,8 @@ pub async fn load_cfd_by_order_id( | |||
let max_quantity = serde_json::from_str(row.max_quantity.as_str()).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing max_quantity
via serde
here is not going to work is it? We are only to_string
ing it on the insert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, all things that involve serde_json::from_str()
will go away with one exception:
// TODO:
// still have the use of serde_json::from_str() here, which will be dealt with
// via https://github.com/comit-network/hermes/issues/290
Ok(Cfd {
order,
quantity_usd: Usd(Decimal::from_str(&row.quantity_usd).unwrap()),
state: serde_json::from_str(row.state.as_str()).unwrap(),
})
daemon/src/model.rs
Outdated
@@ -14,7 +14,8 @@ use uuid::Uuid; | |||
|
|||
pub mod cfd; | |||
|
|||
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq)] | |||
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, sqlx::Type)] | |||
#[sqlx(type_name = "String")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, this only does something for postgres so we can remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unaddressed !
state.state | ||
|
||
from order | ||
inner join state on state.order_id = order.order_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newlines on these.
@@ -0,0 +1,69 @@ | |||
with order as ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer if the changes were made in two steps:
- Moving queries to external files
- Changing up the query to use
with
Actually, all things considered it is not that important to split things up into multiple commits so feel free to squash everything together! Overall, these changes are a major improvement, thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Massive improvement over what we currently have!
- Found what I think is a regression.
- A few unaddressed comments and commits need to be squashed together.
daemon/src/model.rs
Outdated
@@ -14,7 +14,8 @@ use uuid::Uuid; | |||
|
|||
pub mod cfd; | |||
|
|||
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq)] | |||
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, sqlx::Type)] | |||
#[sqlx(type_name = "String")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unaddressed !
ff04b2f
to
e43536a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
2 more tiny changes and this is good to go in. Just amend the now only commit for that (git commit --amend
). Also, can you reword the commit message to something more descriptive please?
Cargo.lock
Outdated
@@ -4,9 +4,9 @@ version = 3 | |||
|
|||
[[package]] | |||
name = "ahash" | |||
version = "0.7.4" | |||
version = "0.7.5" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These update must have been accidental. Can you undo that please?
git checkout master -- Cargo.lock
should do the trick.
}) | ||
} | ||
|
||
pub async fn insert_cfd(cfd: Cfd, conn: &mut PoolConnection<Sqlite>) -> anyhow::Result<()> { | ||
let mut tx = conn.begin().await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! No more transaction for this!
daemon/src/model.rs
Outdated
@@ -13,7 +13,7 @@ use uuid::Uuid; | |||
|
|||
pub mod cfd; | |||
|
|||
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq)] | |||
#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, sqlx::Type)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not actually doing anything because we are not specifying #[sqlx(transparent)]
.
Can you remove it to avoid confusion about what this is doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! Yes, removed now.
The primary goal was to remove all of the calls to `serde_json::to_string()` for the data-handling, thus enabling us to do (more or less): ```rust Order { row.column, ... } ``` as well as clean up the SQL for easier reading. This has mostly been accomplished, with further refinements easily accomplished once the upstream issues in `sqlx` are addressed. See #314 for issues we are tracking.
8687307
to
5cf88a2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Feel free to bors r+
once CI is green.
bors r+ |
DB code refactoring for #88
The primary goal was to remove all of the calls to
serde_json::to_string()
for the data-handling, thus enabling us to do (more or less):as well as clean up the SQL for easier reading. This has mostly been accomplished, with further refinements easily accomplished once the upstream issues in
sqlx
are addressed. See #314 for issues we are tracking.