feat(federation): Restructure transaction_ids service
Adds two new in-memory maps to the service in to prepare for better handlers
This commit is contained in:
parent
526d862296
commit
e986cd4536
1 changed files with 40 additions and 28 deletions
|
|
@ -1,11 +1,22 @@
|
|||
use std::sync::Arc;
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
|
||||
use conduwuit::{Result, implement};
|
||||
use conduwuit::{Result, SyncRwLock};
|
||||
use database::{Handle, Map};
|
||||
use ruma::{DeviceId, TransactionId, UserId};
|
||||
use ruma::{
|
||||
DeviceId, OwnedServerName, OwnedTransactionId, TransactionId, UserId,
|
||||
api::federation::transactions::send_transaction_message,
|
||||
};
|
||||
use tokio::sync::watch::{Receiver, Sender};
|
||||
|
||||
pub type TxnKey = (OwnedServerName, OwnedTransactionId);
|
||||
pub type TxnChanType = (TxnKey, send_transaction_message::v1::Response);
|
||||
pub type ActiveTxnsMapType = HashMap<TxnKey, (Sender<TxnChanType>, Receiver<TxnChanType>)>;
|
||||
|
||||
pub struct Service {
|
||||
db: Data,
|
||||
pub servername_txnid_response_cache:
|
||||
Arc<SyncRwLock<HashMap<TxnKey, send_transaction_message::v1::Response>>>,
|
||||
pub servername_txnid_active: Arc<SyncRwLock<ActiveTxnsMapType>>,
|
||||
}
|
||||
|
||||
struct Data {
|
||||
|
|
@ -18,13 +29,15 @@ impl crate::Service for Service {
|
|||
db: Data {
|
||||
userdevicetxnid_response: args.db["userdevicetxnid_response"].clone(),
|
||||
},
|
||||
servername_txnid_response_cache: Arc::new(SyncRwLock::new(HashMap::new())),
|
||||
servername_txnid_active: Arc::new(SyncRwLock::new(HashMap::new())),
|
||||
}))
|
||||
}
|
||||
|
||||
fn name(&self) -> &str { crate::service::make_name(std::module_path!()) }
|
||||
}
|
||||
|
||||
#[implement(Service)]
|
||||
impl Service {
|
||||
pub fn add_txnid(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
|
@ -41,8 +54,6 @@ pub fn add_txnid(
|
|||
self.db.userdevicetxnid_response.insert(&key, data);
|
||||
}
|
||||
|
||||
// If there's no entry, this is a new transaction
|
||||
#[implement(Service)]
|
||||
pub async fn existing_txnid(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
|
@ -52,3 +63,4 @@ pub async fn existing_txnid(
|
|||
let key = (user_id, device_id, txn_id);
|
||||
self.db.userdevicetxnid_response.qry(&key).await
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue