max / makenotwork
1 file changed,
+5 insertions,
-5 deletions
| @@ -17,15 +17,15 @@ pub async fn create_custom_domain( | |||
| 17 | 17 | ) -> Result<DbCustomDomain> { | |
| 18 | 18 | let mut tx = pool.begin().await?; | |
| 19 | 19 | ||
| 20 | - | // Lock the user row to serialize concurrent domain creation attempts | |
| 21 | - | let existing = sqlx::query_scalar::<_, i64>( | |
| 22 | - | "SELECT COUNT(*) FROM custom_domains WHERE user_id = $1 FOR UPDATE", | |
| 20 | + | // Lock existing rows to serialize concurrent domain creation attempts | |
| 21 | + | let existing: Vec<(CustomDomainId,)> = sqlx::query_as( | |
| 22 | + | "SELECT id FROM custom_domains WHERE user_id = $1 FOR UPDATE", | |
| 23 | 23 | ) | |
| 24 | 24 | .bind(user_id) | |
| 25 | - | .fetch_one(&mut *tx) | |
| 25 | + | .fetch_all(&mut *tx) | |
| 26 | 26 | .await?; | |
| 27 | 27 | ||
| 28 | - | if existing > 0 { | |
| 28 | + | if !existing.is_empty() { | |
| 29 | 29 | return Err(AppError::BadRequest( | |
| 30 | 30 | "You already have a custom domain configured. Remove it first to add a new one.".to_string(), | |
| 31 | 31 | )); |