Skip to content

Commit

Permalink
chore: use upsert to handle conflict
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Zhang <[email protected]>
  • Loading branch information
zwpaper committed Dec 14, 2024
1 parent cd0152e commit 860ca46
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions ee/tabby-db/src/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ impl DbConn {
pub async fn mark_notification_read(&self, id: i64, user_id: i64) -> Result<()> {
query!(
"INSERT INTO read_notifications (notification_id, user_id)
SELECT ?, ?
WHERE NOT EXISTS (
SELECT 1 FROM read_notifications WHERE notification_id = ? AND user_id = ?
)",
VALUES (?, ?)
ON CONFLICT (notification_id, user_id)
DO NOTHING",
id,
user_id,
id,
user_id
)
.execute(&self.pool)
.await?;
Expand Down

0 comments on commit 860ca46

Please sign in to comment.