perf: Don't increment the device list version when updating local info
This commit is contained in:
parent
f3115e14ab
commit
ba55dffa0e
8 changed files with 34 additions and 20 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use axum::extract::State;
|
||||
use conduwuit::{
|
||||
Err, Result, at, err,
|
||||
Err, Result, at,
|
||||
matrix::{
|
||||
event::{Event, Matches},
|
||||
pdu::PduCount,
|
||||
|
|
@ -85,11 +85,11 @@ pub(crate) async fn get_message_events_route(
|
|||
.users
|
||||
.get_device_metadata(sender_user, device_id)
|
||||
.await
|
||||
.or_else(|_| err!(Request(NotFound("device {device_id} not found?"))))?;
|
||||
.expect("Device metadata should exist for authenticated device");
|
||||
device.last_seen_ts = Some(MilliSecondsSinceUnixEpoch::now());
|
||||
services
|
||||
.users
|
||||
.update_device_metadata(sender_user, device_id, &device)
|
||||
.update_device_last_seen(sender_user, device_id, &device)
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,11 +128,11 @@ pub(crate) async fn create_receipt_route(
|
|||
.users
|
||||
.get_device_metadata(sender_user, device_id)
|
||||
.await
|
||||
.or_else(|_| err!(Request(NotFound("device {device_id} not found?"))))?;
|
||||
.expect("Device metadata should exist for authenticated device");
|
||||
device.last_seen_ts = Some(MilliSecondsSinceUnixEpoch::now());
|
||||
services
|
||||
.users
|
||||
.update_device_metadata(sender_user, device_id, &device)
|
||||
.update_device_last_seen(sender_user, device_id, &device)
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use axum::extract::State;
|
||||
use conduwuit::{Err, Result, err, matrix::pdu::PduBuilder};
|
||||
use conduwuit::{Err, Result, matrix::pdu::PduBuilder};
|
||||
use ruma::{
|
||||
MilliSecondsSinceUnixEpoch, api::client::redact::redact_event,
|
||||
events::room::redaction::RoomRedactionEventContent,
|
||||
|
|
@ -24,11 +24,11 @@ pub(crate) async fn redact_event_route(
|
|||
.users
|
||||
.get_device_metadata(sender_user, device_id)
|
||||
.await
|
||||
.or_else(|_| err!(Request(NotFound("device {device_id} not found?"))))?;
|
||||
.expect("Device metadata should exist for authenticated device");
|
||||
device.last_seen_ts = Some(MilliSecondsSinceUnixEpoch::now());
|
||||
services
|
||||
.users
|
||||
.update_device_metadata(sender_user, device_id, &device)
|
||||
.update_device_last_seen(sender_user, device_id, &device)
|
||||
.await?;
|
||||
}
|
||||
let body = &body.body;
|
||||
|
|
|
|||
|
|
@ -32,16 +32,16 @@ pub(crate) async fn send_message_event_route(
|
|||
|
||||
if sender_device.is_some() {
|
||||
// Increment the "device last active" metadata
|
||||
let device_id = sender_device.clone().unwrap();
|
||||
let device_id = sender_device.unwrap();
|
||||
let mut device = services
|
||||
.users
|
||||
.get_device_metadata(sender_user, device_id)
|
||||
.await
|
||||
.or_else(|_| err!(Request(NotFound("device {device_id} not found?"))))?;
|
||||
.expect("Device metadata should exist for authenticated device");
|
||||
device.last_seen_ts = Some(MilliSecondsSinceUnixEpoch::now());
|
||||
services
|
||||
.users
|
||||
.update_device_metadata(sender_user, device_id, &device)
|
||||
.update_device_last_seen(sender_user, device_id, &device)
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,11 +40,11 @@ pub(crate) async fn send_state_event_for_key_route(
|
|||
.users
|
||||
.get_device_metadata(sender_user, device_id)
|
||||
.await
|
||||
.or_else(|_| err!(Request(NotFound("device {device_id} not found?"))))?;
|
||||
.expect("Device metadata should exist for authenticated device");
|
||||
device.last_seen_ts = Some(MilliSecondsSinceUnixEpoch::now());
|
||||
services
|
||||
.users
|
||||
.update_device_metadata(sender_user, device_id, &device)
|
||||
.update_device_last_seen(sender_user, device_id, &device)
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
|
@ -199,7 +199,7 @@ async fn send_state_event_for_key_helper(
|
|||
event_type: &StateEventType,
|
||||
json: &Raw<AnyStateEventContent>,
|
||||
state_key: &str,
|
||||
timestamp: Option<ruma::MilliSecondsSinceUnixEpoch>,
|
||||
timestamp: Option<MilliSecondsSinceUnixEpoch>,
|
||||
) -> Result<OwnedEventId> {
|
||||
allowed_to_send_state_event(services, room_id, event_type, state_key, json).await?;
|
||||
let state_lock = services.rooms.state.mutex.lock(room_id).await;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use std::{
|
|||
|
||||
use axum::extract::State;
|
||||
use conduwuit::{
|
||||
Err, Error, Result, at, err, error, extract_variant, is_equal_to,
|
||||
Err, Error, Result, at, error, extract_variant, is_equal_to,
|
||||
matrix::{Event, TypeStateKey, pdu::PduCount},
|
||||
trace,
|
||||
utils::{
|
||||
|
|
@ -72,11 +72,11 @@ pub(crate) async fn sync_events_v5_route(
|
|||
.users
|
||||
.get_device_metadata(sender_user, sender_device)
|
||||
.await
|
||||
.or_else(|_| err!(Request(NotFound("device {sender_device} not found?"))))?;
|
||||
.expect("Device metadata should exist for authenticated device");
|
||||
device.last_seen_ts = Some(MilliSecondsSinceUnixEpoch::now());
|
||||
services
|
||||
.users
|
||||
.update_device_metadata(sender_user, sender_device, &device)
|
||||
.update_device_last_seen(sender_user, sender_device, &device)
|
||||
.await?;
|
||||
|
||||
let mut body = body.body;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use axum::extract::State;
|
||||
use conduwuit::{Err, Result, err, utils, utils::math::Tried};
|
||||
use conduwuit::{Err, Result, utils, utils::math::Tried};
|
||||
use ruma::{MilliSecondsSinceUnixEpoch, api::client::typing::create_typing_event};
|
||||
|
||||
use crate::Ruma;
|
||||
|
|
@ -20,11 +20,11 @@ pub(crate) async fn create_typing_event_route(
|
|||
.users
|
||||
.get_device_metadata(sender_user, device_id)
|
||||
.await
|
||||
.or_else(|_| err!(Request(NotFound("device {device_id} not found?"))))?;
|
||||
.expect("Device metadata should exist for authenticated device");
|
||||
device.last_seen_ts = Some(MilliSecondsSinceUnixEpoch::now());
|
||||
services
|
||||
.users
|
||||
.update_device_metadata(sender_user, device_id, &device)
|
||||
.update_device_last_seen(sender_user, device_id, &device)
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -980,6 +980,7 @@ impl Service {
|
|||
.await;
|
||||
}
|
||||
|
||||
/// Updates device metadata and increments the device list version.
|
||||
pub async fn update_device_metadata(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
|
@ -987,7 +988,20 @@ impl Service {
|
|||
device: &Device,
|
||||
) -> Result<()> {
|
||||
increment(&self.db.userid_devicelistversion, user_id.as_bytes());
|
||||
self.update_device_last_seen(user_id, device_id, device)
|
||||
.await
|
||||
}
|
||||
|
||||
// Updates device metadata without incrementing the device list version.
|
||||
// This is namely used for updating the last_seen_ip and last_seen_ts values,
|
||||
// as those do not need a device list version bump due to them not being
|
||||
// relevant to other consumers.
|
||||
pub async fn update_device_last_seen(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
device: &Device,
|
||||
) -> Result<()> {
|
||||
let key = (user_id, device_id);
|
||||
self.db.userdeviceid_metadata.put(key, Json(device));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue