Skip to content

Commit

Permalink
refactor: Add fixme to (some) queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Eragonfr committed Oct 19, 2024
1 parent 1c08e86 commit ff5be44
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 3 additions & 0 deletions tokenserver-db-sqlite/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SELECT rowid as id
FROM nodes
WHERE service = ?
AND node = ?"#;
// FIXME: MySQL specific
pub const REPLACE_USERS_SYNC_QUERY: &str = r#"
UPDATE users
SET replaced_at = ?
Expand All @@ -30,6 +31,7 @@ AND email = ?
AND generation <= ?
AND COALESCE(keys_changed_at, 0) <= COALESCE(?, keys_changed_at, 0)
AND replaced_at IS NULL"#;
// FIXME: MySQL specific
pub const POST_USER_SYNC_QUERY: &str = r#"
INSERT INTO users (service, email, generation, client_state, created_at, nodeid, keys_changed_at, replaced_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?);"#;
Expand All @@ -51,6 +53,7 @@ WHERE service = ?
AND available <= 0
AND capacity > current_load
AND downed = 0"#;
// FIXME: MySQL specific
pub const GET_BEST_NODE_SPANNER_QUERY: &str = r#"
SELECT id, node
FROM nodes
Expand Down
3 changes: 1 addition & 2 deletions tokenserver-db/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct DbInner {

impl TokenserverDb {
// Note that this only works because an instance of `TokenserverDb` has *exclusive access* to
// a connection from the r2d2 pool for its lifetime. `LAST_INSERT_ID()`/`LAST_INSERT_ROWID()`
// a connection from the r2d2 pool for its lifetime. `LAST_INSERT_ID_QUERY`
// returns the ID of the most recently-inserted record *for a given connection*.
// If connections were shared across requests, using this function would introduce a race condition,
// as we could potentially get IDs from records created during other requests.
Expand Down Expand Up @@ -163,7 +163,6 @@ impl TokenserverDb {
.execute(&self.inner.conn)?;

diesel::sql_query(LAST_INSERT_ID_QUERY)
.bind::<Text, _>(&user.email)
.get_result::<results::PostUser>(&self.inner.conn)
.map_err(Into::into)
}
Expand Down

0 comments on commit ff5be44

Please sign in to comment.