From d946979b88a8d95b5d3f9e0a3f54dfeeb88916dc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 22:34:57 +0000 Subject: [PATCH] Use UPSERT for ended_timestamp to avoid replacing SDP data Co-authored-by: link2xt <18373967+link2xt@users.noreply.github.com> --- src/calls.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/calls.rs b/src/calls.rs index 02409a047..2b8ce614b 100644 --- a/src/calls.rs +++ b/src/calls.rs @@ -139,12 +139,13 @@ impl CallInfo { self.msg.param.set_i64(CALL_ENDED_TIMESTAMP, now); self.msg.update_param(context).await?; - // Also store ended timestamp in calls table + // Store ended timestamp in calls table. If no entry exists yet, create one. context .sql .execute( - "UPDATE calls SET ended_timestamp=? WHERE msg_id=?", - (now, self.msg.id), + "INSERT INTO calls (msg_id, ended_timestamp) VALUES (?, ?) + ON CONFLICT(msg_id) DO UPDATE SET ended_timestamp=excluded.ended_timestamp", + (self.msg.id, now), ) .await?; Ok(()) @@ -163,12 +164,13 @@ impl CallInfo { self.msg.param.set_i64(CALL_CANCELED_TIMESTAMP, now); self.msg.update_param(context).await?; - // Also store ended timestamp in calls table + // Store ended timestamp in calls table. If no entry exists yet, create one. context .sql .execute( - "UPDATE calls SET ended_timestamp=? WHERE msg_id=?", - (now, self.msg.id), + "INSERT INTO calls (msg_id, ended_timestamp) VALUES (?, ?) + ON CONFLICT(msg_id) DO UPDATE SET ended_timestamp=excluded.ended_timestamp", + (self.msg.id, now), ) .await?; Ok(())