perf: Throttle frequent device metadata updates & centralise site

This commit is contained in:
timedout
2025-12-02 14:46:13 +00:00
parent ba55dffa0e
commit 393d341f07
8 changed files with 76 additions and 106 deletions
+7 -16
View File
@@ -1,8 +1,8 @@
use axum::extract::State;
use axum_client_ip::InsecureClientIp;
use conduwuit::{Err, Result, matrix::pdu::PduBuilder};
use ruma::{
MilliSecondsSinceUnixEpoch, api::client::redact::redact_event,
events::room::redaction::RoomRedactionEventContent,
api::client::redact::redact_event, events::room::redaction::RoomRedactionEventContent,
};
use crate::Ruma;
@@ -14,23 +14,14 @@ use crate::Ruma;
/// - TODO: Handle txn id
pub(crate) async fn redact_event_route(
State(services): State<crate::State>,
InsecureClientIp(client_ip): InsecureClientIp,
body: Ruma<redact_event::v3::Request>,
) -> Result<redact_event::v3::Response> {
let sender_user = body.sender_user();
if body.sender_device.is_some() {
// Increment the "device last active" metadata
let device_id = body.sender_device();
let mut device = services
.users
.get_device_metadata(sender_user, device_id)
.await
.expect("Device metadata should exist for authenticated device");
device.last_seen_ts = Some(MilliSecondsSinceUnixEpoch::now());
services
.users
.update_device_last_seen(sender_user, device_id, &device)
.await?;
}
services
.users
.update_device_last_seen(sender_user, body.sender_device.as_deref(), client_ip)
.await;
let body = &body.body;
if services.users.is_suspended(sender_user).await? {
// TODO: Users can redact their own messages while suspended