optimize get w/ zero-copy ref handle

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-02 05:56:10 +00:00
parent 0522fe7d92
commit ee64fb149c
11 changed files with 46 additions and 16 deletions

View file

@ -39,7 +39,7 @@ impl Data {
pub(super) fn remove_alias(&self, alias: &RoomAliasId) -> Result<()> {
if let Some(room_id) = self.alias_roomid.get(alias.alias().as_bytes())? {
let mut prefix = room_id;
let mut prefix = room_id.to_vec();
prefix.push(0xFF);
for (key, _) in self.aliasid_alias.scan_prefix(prefix) {

View file

@ -83,7 +83,7 @@ impl Service {
) -> Result<Option<Vec<u8>>> {
// 1. Skip the PDU if we already have it as a timeline event
if let Some(pdu_id) = services().rooms.timeline.get_pdu_id(event_id)? {
return Ok(Some(pdu_id));
return Ok(Some(pdu_id.to_vec()));
}
// 1.1 Check the server is in the room
@ -449,7 +449,7 @@ impl Service {
) -> Result<Option<Vec<u8>>> {
// Skip the PDU if we already have it as a timeline event
if let Ok(Some(pduid)) = services().rooms.timeline.get_pdu_id(&incoming_pdu.event_id) {
return Ok(Some(pduid));
return Ok(Some(pduid.to_vec()));
}
if services()

View file

@ -93,7 +93,7 @@ impl Data {
}
/// Returns the pdu's id.
pub(super) fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<Vec<u8>>> {
pub(super) fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<database::Handle<'_>>> {
self.eventid_pduid.get(event_id.as_bytes())
}

View file

@ -159,7 +159,9 @@ impl Service {
}
/// Returns the pdu's id.
pub fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<Vec<u8>>> { self.db.get_pdu_id(event_id) }
pub fn get_pdu_id(&self, event_id: &EventId) -> Result<Option<database::Handle<'_>>> {
self.db.get_pdu_id(event_id)
}
/// Returns the pdu.
///
@ -1185,7 +1187,8 @@ impl Service {
// Skip the PDU if we already have it as a timeline event
if let Some(pdu_id) = self.get_pdu_id(&event_id)? {
info!("We already know {event_id} at {pdu_id:?}");
let pdu_id = pdu_id.to_vec();
debug!("We already know {event_id} at {pdu_id:?}");
return Ok(());
}