mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-07-31 20:28:31 +00:00
refactor for stronger RawPduId type
implement standard traits for PduCount enable serde for arrayvec typedef various shortid's pducount simplifications split parts of pdu_metadata service to core/pdu and api/relations remove some yields; improve var names/syntax tweak types for limit timeline limit arguments Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
2e4d9cb37c
commit
9da523c004
41 changed files with 796 additions and 573 deletions
|
@ -115,10 +115,10 @@ impl Data {
|
|||
let mut keys = Vec::new();
|
||||
for (event, destination) in requests {
|
||||
let mut key = destination.get_prefix();
|
||||
if let SendingEvent::Pdu(value) = &event {
|
||||
key.extend_from_slice(value);
|
||||
if let SendingEvent::Pdu(value) = event {
|
||||
key.extend(value.as_ref());
|
||||
} else {
|
||||
key.extend_from_slice(&self.services.globals.next_count().unwrap().to_be_bytes());
|
||||
key.extend(&self.services.globals.next_count().unwrap().to_be_bytes());
|
||||
}
|
||||
let value = if let SendingEvent::Edu(value) = &event {
|
||||
&**value
|
||||
|
@ -175,7 +175,7 @@ fn parse_servercurrentevent(key: &[u8], value: &[u8]) -> Result<(Destination, Se
|
|||
(
|
||||
Destination::Appservice(server),
|
||||
if value.is_empty() {
|
||||
SendingEvent::Pdu(event.to_vec())
|
||||
SendingEvent::Pdu(event.into())
|
||||
} else {
|
||||
SendingEvent::Edu(value.to_vec())
|
||||
},
|
||||
|
@ -202,7 +202,7 @@ fn parse_servercurrentevent(key: &[u8], value: &[u8]) -> Result<(Destination, Se
|
|||
(
|
||||
Destination::Push(user_id, pushkey_string),
|
||||
if value.is_empty() {
|
||||
SendingEvent::Pdu(event.to_vec())
|
||||
SendingEvent::Pdu(event.into())
|
||||
} else {
|
||||
// I'm pretty sure this should never be called
|
||||
SendingEvent::Edu(value.to_vec())
|
||||
|
@ -225,7 +225,7 @@ fn parse_servercurrentevent(key: &[u8], value: &[u8]) -> Result<(Destination, Se
|
|||
.map_err(|_| Error::bad_database("Invalid server string in server_currenttransaction"))?,
|
||||
),
|
||||
if value.is_empty() {
|
||||
SendingEvent::Pdu(event.to_vec())
|
||||
SendingEvent::Pdu(event.into())
|
||||
} else {
|
||||
SendingEvent::Edu(value.to_vec())
|
||||
},
|
||||
|
|
|
@ -24,7 +24,10 @@ pub use self::{
|
|||
dest::Destination,
|
||||
sender::{EDU_LIMIT, PDU_LIMIT},
|
||||
};
|
||||
use crate::{account_data, client, globals, presence, pusher, resolver, rooms, server_keys, users, Dep};
|
||||
use crate::{
|
||||
account_data, client, globals, presence, pusher, resolver, rooms, rooms::timeline::RawPduId, server_keys, users,
|
||||
Dep,
|
||||
};
|
||||
|
||||
pub struct Service {
|
||||
server: Arc<Server>,
|
||||
|
@ -61,9 +64,9 @@ struct Msg {
|
|||
#[allow(clippy::module_name_repetitions)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum SendingEvent {
|
||||
Pdu(Vec<u8>), // pduid
|
||||
Edu(Vec<u8>), // pdu json
|
||||
Flush, // none
|
||||
Pdu(RawPduId), // pduid
|
||||
Edu(Vec<u8>), // pdu json
|
||||
Flush, // none
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
@ -110,9 +113,9 @@ impl crate::Service for Service {
|
|||
|
||||
impl Service {
|
||||
#[tracing::instrument(skip(self, pdu_id, user, pushkey), level = "debug")]
|
||||
pub fn send_pdu_push(&self, pdu_id: &[u8], user: &UserId, pushkey: String) -> Result<()> {
|
||||
pub fn send_pdu_push(&self, pdu_id: &RawPduId, user: &UserId, pushkey: String) -> Result {
|
||||
let dest = Destination::Push(user.to_owned(), pushkey);
|
||||
let event = SendingEvent::Pdu(pdu_id.to_owned());
|
||||
let event = SendingEvent::Pdu(*pdu_id);
|
||||
let _cork = self.db.db.cork();
|
||||
let keys = self.db.queue_requests(&[(&event, &dest)]);
|
||||
self.dispatch(Msg {
|
||||
|
@ -123,7 +126,7 @@ impl Service {
|
|||
}
|
||||
|
||||
#[tracing::instrument(skip(self), level = "debug")]
|
||||
pub fn send_pdu_appservice(&self, appservice_id: String, pdu_id: Vec<u8>) -> Result<()> {
|
||||
pub fn send_pdu_appservice(&self, appservice_id: String, pdu_id: RawPduId) -> Result {
|
||||
let dest = Destination::Appservice(appservice_id);
|
||||
let event = SendingEvent::Pdu(pdu_id);
|
||||
let _cork = self.db.db.cork();
|
||||
|
@ -136,7 +139,7 @@ impl Service {
|
|||
}
|
||||
|
||||
#[tracing::instrument(skip(self, room_id, pdu_id), level = "debug")]
|
||||
pub async fn send_pdu_room(&self, room_id: &RoomId, pdu_id: &[u8]) -> Result<()> {
|
||||
pub async fn send_pdu_room(&self, room_id: &RoomId, pdu_id: &RawPduId) -> Result {
|
||||
let servers = self
|
||||
.services
|
||||
.state_cache
|
||||
|
@ -147,13 +150,13 @@ impl Service {
|
|||
}
|
||||
|
||||
#[tracing::instrument(skip(self, servers, pdu_id), level = "debug")]
|
||||
pub async fn send_pdu_servers<'a, S>(&self, servers: S, pdu_id: &[u8]) -> Result<()>
|
||||
pub async fn send_pdu_servers<'a, S>(&self, servers: S, pdu_id: &RawPduId) -> Result
|
||||
where
|
||||
S: Stream<Item = &'a ServerName> + Send + 'a,
|
||||
{
|
||||
let _cork = self.db.db.cork();
|
||||
let requests = servers
|
||||
.map(|server| (Destination::Normal(server.into()), SendingEvent::Pdu(pdu_id.into())))
|
||||
.map(|server| (Destination::Normal(server.into()), SendingEvent::Pdu(pdu_id.to_owned())))
|
||||
.collect::<Vec<_>>()
|
||||
.await;
|
||||
|
||||
|
|
|
@ -536,7 +536,8 @@ impl Service {
|
|||
&events
|
||||
.iter()
|
||||
.map(|e| match e {
|
||||
SendingEvent::Edu(b) | SendingEvent::Pdu(b) => &**b,
|
||||
SendingEvent::Edu(b) => &**b,
|
||||
SendingEvent::Pdu(b) => b.as_ref(),
|
||||
SendingEvent::Flush => &[],
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
|
@ -660,7 +661,8 @@ impl Service {
|
|||
&events
|
||||
.iter()
|
||||
.map(|e| match e {
|
||||
SendingEvent::Edu(b) | SendingEvent::Pdu(b) => &**b,
|
||||
SendingEvent::Edu(b) => &**b,
|
||||
SendingEvent::Pdu(b) => b.as_ref(),
|
||||
SendingEvent::Flush => &[],
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue