Add wrapper types for short IDs

This commit is contained in:
Lambda 2024-08-27 14:27:12 +00:00
parent f1642c92d1
commit b0f33207fe
28 changed files with 427 additions and 232 deletions

View file

@ -2,7 +2,10 @@ use ruma::RoomId;
use crate::{
database::KeyValueDatabase,
service::{self, rooms::timeline::PduId},
service::{
self,
rooms::{short::ShortRoomId, timeline::PduId},
},
services, utils, Result,
};
@ -21,12 +24,12 @@ impl service::rooms::search::Data for KeyValueDatabase {
#[tracing::instrument(skip(self))]
fn index_pdu(
&self,
shortroomid: u64,
shortroomid: ShortRoomId,
pdu_id: &PduId,
message_body: &str,
) -> Result<()> {
let mut batch = tokenize(message_body).map(|word| {
let mut key = shortroomid.to_be_bytes().to_vec();
let mut key = shortroomid.get().to_be_bytes().to_vec();
key.extend_from_slice(word.as_bytes());
key.push(0xFF);
// TODO: currently we save the room id a second time here
@ -40,12 +43,12 @@ impl service::rooms::search::Data for KeyValueDatabase {
#[tracing::instrument(skip(self))]
fn deindex_pdu(
&self,
shortroomid: u64,
shortroomid: ShortRoomId,
pdu_id: &PduId,
message_body: &str,
) -> Result<()> {
let batch = tokenize(message_body).map(|word| {
let mut key = shortroomid.to_be_bytes().to_vec();
let mut key = shortroomid.get().to_be_bytes().to_vec();
key.extend_from_slice(word.as_bytes());
key.push(0xFF);
// TODO: currently we save the room id a second time here
@ -73,6 +76,7 @@ impl service::rooms::search::Data for KeyValueDatabase {
.short
.get_shortroomid(room_id)?
.expect("room exists")
.get()
.to_be_bytes()
.to_vec();