mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
Improve calls table with FOREIGN KEY, STRICT mode, and better housekeeping query
Co-authored-by: link2xt <18373967+link2xt@users.noreply.github.com>
This commit is contained in:
@@ -509,7 +509,10 @@ impl Context {
|
|||||||
|
|
||||||
// Loads information about the call given the `Message`.
|
// Loads information about the call given the `Message`.
|
||||||
//
|
//
|
||||||
// If the `Message` is not a call message, returns `None`
|
// If the `Message` is not a call message, returns `None`.
|
||||||
|
//
|
||||||
|
// This function is async because it queries the calls table
|
||||||
|
// to retrieve SDP offers and answers.
|
||||||
async fn load_call_by_message(&self, call: Message) -> Result<Option<CallInfo>> {
|
async fn load_call_by_message(&self, call: Message) -> Result<Option<CallInfo>> {
|
||||||
if call.viewtype != Viewtype::Call {
|
if call.viewtype != Viewtype::Call {
|
||||||
// This can happen e.g. if a "call accepted"
|
// This can happen e.g. if a "call accepted"
|
||||||
|
|||||||
11
src/sql.rs
11
src/sql.rs
@@ -922,17 +922,18 @@ pub async fn housekeeping(context: &Context) -> Result<()> {
|
|||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
// Delete call SDPs for ended calls (older than 24 hours) or orphaned calls.
|
// Delete call SDPs for ended calls (older than 24 hours) or orphaned calls.
|
||||||
// Ended calls have Param::Arg4 (H=timestamp) set in their params.
|
|
||||||
// We clean up calls that ended more than 24 hours ago to protect privacy
|
// We clean up calls that ended more than 24 hours ago to protect privacy
|
||||||
// as SDPs contain IP addresses.
|
// as SDPs contain IP addresses. Ended calls are identified by having
|
||||||
|
// the CALL_ENDED_TIMESTAMP parameter (Param::Arg4) set.
|
||||||
|
// The ON DELETE CASCADE foreign key will handle orphaned entries automatically,
|
||||||
|
// but we also check for trash and old ended calls.
|
||||||
context
|
context
|
||||||
.sql
|
.sql
|
||||||
.execute(
|
.execute(
|
||||||
"DELETE FROM calls WHERE msg_id IN (
|
"DELETE FROM calls WHERE msg_id IN (
|
||||||
SELECT calls.msg_id FROM calls
|
SELECT calls.msg_id FROM calls
|
||||||
LEFT JOIN msgs ON calls.msg_id = msgs.id
|
INNER JOIN msgs ON calls.msg_id = msgs.id
|
||||||
WHERE msgs.id IS NULL
|
WHERE msgs.chat_id = ?
|
||||||
OR msgs.chat_id = ?
|
|
||||||
OR (msgs.param LIKE '%H=%'
|
OR (msgs.param LIKE '%H=%'
|
||||||
AND msgs.timestamp_sent < ?)
|
AND msgs.timestamp_sent < ?)
|
||||||
)",
|
)",
|
||||||
|
|||||||
@@ -1344,10 +1344,10 @@ CREATE INDEX gossip_timestamp_index ON gossip_timestamp (chat_id, fingerprint);
|
|||||||
sql.execute_migration(
|
sql.execute_migration(
|
||||||
"CREATE TABLE calls(
|
"CREATE TABLE calls(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
msg_id INTEGER NOT NULL UNIQUE,
|
msg_id INTEGER NOT NULL UNIQUE REFERENCES msgs(id) ON DELETE CASCADE,
|
||||||
offer_sdp TEXT,
|
offer_sdp TEXT,
|
||||||
answer_sdp TEXT
|
answer_sdp TEXT
|
||||||
);
|
) STRICT;
|
||||||
CREATE INDEX calls_msg_id_index ON calls (msg_id);",
|
CREATE INDEX calls_msg_id_index ON calls (msg_id);",
|
||||||
migration_version,
|
migration_version,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user