summaryrefslogtreecommitdiffstats
path: root/src/routes/user.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv@tobyvin.dev>2024-04-09 15:13:12 -0500
committerToby Vincent <tobyv@tobyvin.dev>2024-04-11 23:50:13 -0500
commiteb8a597d310d8948d0b5a02911dd2002f00cfb39 (patch)
tree62bd417be9d5ac10678a98f095e038462e170228 /src/routes/user.rs
parent78a81465409fba33648701c8a20660259e16a807 (diff)
perf: limit results for fetch_optional queries
Diffstat (limited to 'src/routes/user.rs')
-rw-r--r--src/routes/user.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/routes/user.rs b/src/routes/user.rs
index 04ab500..73eef04 100644
--- a/src/routes/user.rs
+++ b/src/routes/user.rs
@@ -18,11 +18,15 @@ impl UserUuid {
/// Get a user with a specific `uuid`
#[tracing::instrument]
pub async fn get(self, State(state): State<Arc<AppState>>) -> impl IntoResponse {
- sqlx::query_as!(UserSchema, "SELECT * FROM users WHERE uuid = $1", self.uuid)
- .fetch_optional(&state.pool)
- .await?
- .ok_or_else(|| Error::UserNotFound)
- .map(Json)
+ sqlx::query_as!(
+ UserSchema,
+ "SELECT * FROM users WHERE uuid = $1 LIMIT 1",
+ self.uuid
+ )
+ .fetch_optional(&state.pool)
+ .await?
+ .ok_or_else(|| Error::UserNotFound)
+ .map(Json)
}
}
@@ -37,11 +41,15 @@ impl User {
State(state): State<Arc<AppState>>,
Extension(Claims { sub, .. }): Extension<Claims>,
) -> Result<impl IntoResponse, Error> {
- sqlx::query_as!(UserSchema, "SELECT * FROM users WHERE uuid = $1", sub)
- .fetch_optional(&state.pool)
- .await?
- .ok_or_else(|| Error::UserNotFound)
- .map(Json)
+ sqlx::query_as!(
+ UserSchema,
+ "SELECT * FROM users WHERE uuid = $1 LIMIT 1",
+ sub
+ )
+ .fetch_optional(&state.pool)
+ .await?
+ .ok_or_else(|| Error::UserNotFound)
+ .map(Json)
}
}