-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor to avoid using SELECT *
#107
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 :D
You seem to have missed a couple of instances (like this one).
ps. run git grep -n "SELECT.*\*"
to get them all.
It is fixed. |
It is ready |
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.
Some minimal changes.
There are two additional instances of SELECT *
in the codebase, but they are used to check if a row exists, so I'm guessing they are OK.
Needs rebasing.
teos/src/dbm.rs
Outdated
@@ -306,7 +316,9 @@ impl DBM { | |||
) -> HashMap<UUID, ExtendedAppointment> { | |||
let mut appointments = HashMap::new(); | |||
|
|||
let mut sql = "SELECT * FROM appointments as a LEFT JOIN trackers as t ON a.UUID=t.UUID WHERE t.UUID IS NULL".to_string(); | |||
let mut sql = | |||
"SELECT a.UUID, locator, encrypted_blob, to_self_delay, user_signature, start_block, user_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.
Prepend all fields with a.
for consistency.
e.g:
a.UUID, a.locator, ...
teos/src/dbm.rs
Outdated
"SELECT t.*, a.user_id FROM trackers as t INNER JOIN appointments as a ON t.UUID=a.UUID WHERE t.UUID=(?)").unwrap(); | ||
let mut stmt = self | ||
.connection.prepare( | ||
"SELECT dispute_tx, penalty_tx, height, confirmed, a.user_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.
Same here with t.
:
t.dispute_tx, t.penalty_tx, ...
teos/src/dbm.rs
Outdated
@@ -478,7 +495,9 @@ impl DBM { | |||
) -> HashMap<UUID, TransactionTracker> { | |||
let mut trackers = HashMap::new(); | |||
|
|||
let mut sql = "SELECT t.*, a.user_id FROM trackers as t INNER JOIN appointments as a ON t.UUID=a.UUID".to_string(); | |||
let mut sql = "SELECT t.UUID, dispute_tx, penalty_tx, height, confirmed, a.user_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.
Same as above: t.
...
watchtower-plugin/src/dbm.rs
Outdated
@@ -533,7 +533,7 @@ impl DBM { | |||
let mut appointments = Vec::new(); | |||
let mut stmt = self | |||
.connection | |||
.prepare(&format!("SELECT * FROM appointments as a, {} as t WHERE a.locator = t.locator AND t.tower_id = ?", table)) | |||
.prepare(&format!("SELECT a.locator, encrypted_blob, to_self_delay FROM appointments as a, {} as t WHERE a.locator = t.locator AND t.tower_id = ?", table)) |
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.
And same with a.
...
watchtower-plugin/src/dbm.rs
Outdated
@@ -533,7 +533,7 @@ impl DBM { | |||
let mut appointments = Vec::new(); | |||
let mut stmt = self | |||
.connection | |||
.prepare(&format!("SELECT * FROM appointments as a, {} as t WHERE a.locator = t.locator AND t.tower_id = ?", table)) | |||
.prepare(&format!("SELECT a.locator, encrypted_blob, to_self_delay FROM appointments as a, {} as t WHERE a.locator = t.locator AND t.tower_id = ?", table)) |
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.
And same with a.
...
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.
Some minimal changes.
There are two additional instances of SELECT *
in the codebase, but they are used to check if a row exists, so I'm guessing they are OK.
Needs rebasing.
Applied changes and rebased. |
@JonathanPlasse Same with this one, sorry I missed it. Maybe fix #110 first and once that's merged rebase this so we can merge it too. |
Needs rebase |
Rebased. |
Close #105