Skip to content

Commit 16b3b8a

Browse files
Fold mailbox connected timestamp into claims (#238)
Remove the extra per-session mark_connected update by setting last_connected_at when a mailbox row is claimed.
1 parent baa6940 commit 16b3b8a

3 files changed

Lines changed: 12 additions & 31 deletions

File tree

server/src/db/mailbox_authorization_repo.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ impl<'a> MailboxAuthorizationRepository<'a> {
177177
UPDATE mailbox_authorizations AS mailbox
178178
SET lease_owner = $3,
179179
lease_expires_at = $5,
180+
last_connected_at = now(),
180181
updated_at = now()
181182
FROM candidates
182183
WHERE mailbox.pubkey = candidates.pubkey
@@ -243,30 +244,6 @@ impl<'a> MailboxAuthorizationRepository<'a> {
243244
Ok(result.rows_affected() > 0)
244245
}
245246

246-
pub async fn mark_connected(
247-
&self,
248-
pubkey: &str,
249-
auth_version: i64,
250-
worker_id: &str,
251-
) -> Result<bool> {
252-
let result = sqlx::query(
253-
"UPDATE mailbox_authorizations
254-
SET last_connected_at = now(),
255-
status = 'active',
256-
updated_at = now()
257-
WHERE pubkey = $1
258-
AND auth_version = $2
259-
AND lease_owner = $3",
260-
)
261-
.bind(pubkey)
262-
.bind(auth_version)
263-
.bind(worker_id)
264-
.execute(self.pool)
265-
.await?;
266-
267-
Ok(result.rows_affected() > 0)
268-
}
269-
270247
pub async fn current_failure_count(&self, pubkey: &str) -> Result<i32> {
271248
let count = sqlx::query_scalar::<_, i32>(
272249
"SELECT failure_count

server/src/mailbox_worker.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,6 @@ where
425425
T: MailboxTransport + 'static,
426426
{
427427
let repo = MailboxAuthorizationRepository::new(&app_state.db_pool);
428-
let is_connected = repo
429-
.mark_connected(&mailbox.pubkey, mailbox.auth_version, &worker_id)
430-
.await?;
431-
if !is_connected {
432-
return Ok(());
433-
}
434-
435428
let session = MailboxSessionContext {
436429
worker_id: worker_id.clone(),
437430
stream_idle_reconnect: config.stream_idle_reconnect,

server/src/tests/gated_auth_tests.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,17 @@ async fn test_claim_runnable_mailboxes_is_exclusive_per_worker() {
602602
assert_eq!(first_claim.len(), 1);
603603
assert_eq!(first_claim[0].pubkey, user.pubkey().to_string());
604604
assert_eq!(second_claim.len(), 0);
605+
606+
let last_connected_at = sqlx::query_scalar::<_, Option<chrono::DateTime<Utc>>>(
607+
"SELECT last_connected_at
608+
FROM mailbox_authorizations
609+
WHERE pubkey = $1",
610+
)
611+
.bind(user.pubkey().to_string())
612+
.fetch_one(&app_state.db_pool)
613+
.await
614+
.unwrap();
615+
assert!(last_connected_at.is_some());
605616
}
606617

607618
#[tracing_test::traced_test]

0 commit comments

Comments
 (0)