Services refactor

Replace structs of Dep<Service> with OnceServices, so each service has a Services reference

Remove service name => Service map

Flatten Services.rooms

Make reqwest Clients lazy initialized (client service)
This commit is contained in:
dasha_uwu
2025-08-22 20:15:54 +05:00
parent 26b3a84b88
commit b5890b9664
118 changed files with 457 additions and 1923 deletions

View File

@@ -8,17 +8,17 @@ use ruma::{
events::StateEventType,
};
use tuwunel_core::{
Err, Result, Server, err,
Err, Result, err,
matrix::Event,
utils::{ReadyExt, stream::TryIgnore},
};
use tuwunel_database::{Deserialized, Ignore, Interfix, Map};
use crate::{Dep, admin, appservice, appservice::RegistrationInfo, globals, rooms, sending};
use crate::appservice::RegistrationInfo;
pub struct Service {
db: Data,
services: Services,
services: Arc<crate::services::OnceServices>,
}
struct Data {
@@ -27,15 +27,6 @@ struct Data {
aliasid_alias: Arc<Map>,
}
struct Services {
server: Arc<Server>,
admin: Dep<admin::Service>,
appservice: Dep<appservice::Service>,
globals: Dep<globals::Service>,
sending: Dep<sending::Service>,
state_accessor: Dep<rooms::state_accessor::Service>,
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
@@ -44,15 +35,7 @@ impl crate::Service for Service {
alias_roomid: args.db["alias_roomid"].clone(),
aliasid_alias: args.db["aliasid_alias"].clone(),
},
services: Services {
server: args.server.clone(),
admin: args.depend::<admin::Service>("admin"),
appservice: args.depend::<appservice::Service>("appservice"),
globals: args.depend::<globals::Service>("globals"),
sending: args.depend::<sending::Service>("sending"),
state_accessor: args
.depend::<rooms::state_accessor::Service>("rooms::state_accessor"),
},
services: args.services.clone(),
}))
}

View File

@@ -21,29 +21,19 @@ use tuwunel_core::{
};
use self::data::Data;
use crate::{Dep, rooms, rooms::short::ShortEventId};
use crate::rooms::short::ShortEventId;
pub struct Service {
services: Services,
services: Arc<crate::services::OnceServices>,
db: Data,
}
struct Services {
short: Dep<rooms::short::Service>,
state: Dep<rooms::state::Service>,
timeline: Dep<rooms::timeline::Service>,
}
type Bucket<'a> = BTreeSet<(u64, &'a EventId)>;
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
services: Services {
short: args.depend::<rooms::short::Service>("rooms::short"),
state: args.depend::<rooms::state::Service>("rooms::state"),
timeline: args.depend::<rooms::timeline::Service>("rooms::timeline"),
},
services: args.services.clone(),
db: Data::new(&args),
}))
}

View File

@@ -21,31 +21,14 @@ use std::{
use async_trait::async_trait;
use ruma::{EventId, OwnedRoomId, RoomId};
use tuwunel_core::{
Err, Result, Server, implement,
Err, Result, implement,
matrix::{Event, PduEvent},
utils::{MutexMap, continue_exponential_backoff},
};
use crate::{Dep, globals, rooms, sending, server_keys};
pub struct Service {
pub mutex_federation: RoomMutexMap,
services: Services,
}
struct Services {
globals: Dep<globals::Service>,
sending: Dep<sending::Service>,
auth_chain: Dep<rooms::auth_chain::Service>,
metadata: Dep<rooms::metadata::Service>,
pdu_metadata: Dep<rooms::pdu_metadata::Service>,
server_keys: Dep<server_keys::Service>,
short: Dep<rooms::short::Service>,
state: Dep<rooms::state::Service>,
state_accessor: Dep<rooms::state_accessor::Service>,
state_compressor: Dep<rooms::state_compressor::Service>,
timeline: Dep<rooms::timeline::Service>,
server: Arc<Server>,
services: Arc<crate::services::OnceServices>,
}
type RoomMutexMap = MutexMap<OwnedRoomId, ()>;
@@ -55,22 +38,7 @@ impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
mutex_federation: RoomMutexMap::new(),
services: Services {
globals: args.depend::<globals::Service>("globals"),
sending: args.depend::<sending::Service>("sending"),
auth_chain: args.depend::<rooms::auth_chain::Service>("rooms::auth_chain"),
metadata: args.depend::<rooms::metadata::Service>("rooms::metadata"),
server_keys: args.depend::<server_keys::Service>("server_keys"),
pdu_metadata: args.depend::<rooms::pdu_metadata::Service>("rooms::pdu_metadata"),
short: args.depend::<rooms::short::Service>("rooms::short"),
state: args.depend::<rooms::state::Service>("rooms::state"),
state_accessor: args
.depend::<rooms::state_accessor::Service>("rooms::state_accessor"),
state_compressor: args
.depend::<rooms::state_compressor::Service>("rooms::state_compressor"),
timeline: args.depend::<rooms::timeline::Service>("rooms::timeline"),
server: args.server.clone(),
},
services: args.services.clone(),
}))
}

View File

@@ -11,11 +11,9 @@ use tuwunel_core::{
};
use tuwunel_database::Map;
use crate::{Dep, rooms};
pub struct Service {
db: Data,
services: Services,
services: Arc<crate::services::OnceServices>,
}
struct Data {
@@ -25,12 +23,6 @@ struct Data {
pduid_pdu: Arc<Map>,
}
struct Services {
directory: Dep<rooms::directory::Service>,
short: Dep<rooms::short::Service>,
state_accessor: Dep<rooms::state_accessor::Service>,
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
@@ -40,12 +32,7 @@ impl crate::Service for Service {
roomid_shortroomid: args.db["roomid_shortroomid"].clone(),
pduid_pdu: args.db["pduid_pdu"].clone(),
},
services: Services {
directory: args.depend::<rooms::directory::Service>("rooms::directory"),
short: args.depend::<rooms::short::Service>("rooms::short"),
state_accessor: args
.depend::<rooms::state_accessor::Service>("rooms::state_accessor"),
},
services: args.services.clone(),
}))
}

View File

@@ -17,27 +17,3 @@ pub mod threads;
pub mod timeline;
pub mod typing;
pub mod user;
use std::sync::Arc;
pub struct Service {
pub alias: Arc<alias::Service>,
pub auth_chain: Arc<auth_chain::Service>,
pub directory: Arc<directory::Service>,
pub event_handler: Arc<event_handler::Service>,
pub lazy_loading: Arc<lazy_loading::Service>,
pub metadata: Arc<metadata::Service>,
pub pdu_metadata: Arc<pdu_metadata::Service>,
pub read_receipt: Arc<read_receipt::Service>,
pub search: Arc<search::Service>,
pub short: Arc<short::Service>,
pub spaces: Arc<spaces::Service>,
pub state: Arc<state::Service>,
pub state_accessor: Arc<state_accessor::Service>,
pub state_cache: Arc<state_cache::Service>,
pub state_compressor: Arc<state_compressor::Service>,
pub threads: Arc<threads::Service>,
pub timeline: Arc<timeline::Service>,
pub typing: Arc<typing::Service>,
pub user: Arc<user::Service>,
}

View File

@@ -14,23 +14,16 @@ use tuwunel_core::{
};
use tuwunel_database::Map;
use crate::{
Dep, rooms,
rooms::{
short::{ShortEventId, ShortRoomId},
timeline::{PduId, RawPduId},
},
use crate::rooms::{
short::{ShortEventId, ShortRoomId},
timeline::{PduId, RawPduId},
};
pub(super) struct Data {
tofrom_relation: Arc<Map>,
referencedevents: Arc<Map>,
softfailedeventids: Arc<Map>,
services: Services,
}
struct Services {
timeline: Dep<rooms::timeline::Service>,
services: Arc<crate::services::OnceServices>,
}
impl Data {
@@ -40,9 +33,7 @@ impl Data {
tofrom_relation: db["tofrom_relation"].clone(),
referencedevents: db["referencedevents"].clone(),
softfailedeventids: db["softfailedeventids"].clone(),
services: Services {
timeline: args.depend::<rooms::timeline::Service>("rooms::timeline"),
},
services: args.services.clone(),
}
}

View File

@@ -9,25 +9,16 @@ use tuwunel_core::{
};
use self::data::Data;
use crate::{Dep, rooms};
pub struct Service {
services: Services,
services: Arc<crate::services::OnceServices>,
db: Data,
}
struct Services {
short: Dep<rooms::short::Service>,
timeline: Dep<rooms::timeline::Service>,
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
services: Services {
short: args.depend::<rooms::short::Service>("rooms::short"),
timeline: args.depend::<rooms::timeline::Service>("rooms::timeline"),
},
services: args.services.clone(),
db: Data::new(&args),
}))
}

View File

@@ -12,19 +12,13 @@ use tuwunel_core::{
};
use tuwunel_database::{Deserialized, Json, Map};
use crate::{Dep, globals};
pub(super) struct Data {
roomuserid_privateread: Arc<Map>,
roomuserid_lastprivatereadupdate: Arc<Map>,
services: Services,
services: Arc<crate::services::OnceServices>,
readreceiptid_readreceipt: Arc<Map>,
}
struct Services {
globals: Dep<globals::Service>,
}
pub(super) type ReceiptItem<'a> = (&'a UserId, u64, Raw<AnySyncEphemeralRoomEvent>);
impl Data {
@@ -34,9 +28,7 @@ impl Data {
roomuserid_privateread: db["roomuserid_privateread"].clone(),
roomuserid_lastprivatereadupdate: db["roomuserid_lastprivatereadupdate"].clone(),
readreceiptid_readreceipt: db["readreceiptid_readreceipt"].clone(),
services: Services {
globals: args.depend::<globals::Service>("globals"),
},
services: args.services.clone(),
}
}

View File

@@ -21,27 +21,16 @@ use tuwunel_core::{
};
use self::data::{Data, ReceiptItem};
use crate::{Dep, rooms, sending};
pub struct Service {
services: Services,
services: Arc<crate::services::OnceServices>,
db: Data,
}
struct Services {
sending: Dep<sending::Service>,
short: Dep<rooms::short::Service>,
timeline: Dep<rooms::timeline::Service>,
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
services: Services {
sending: args.depend::<sending::Service>("sending"),
short: args.depend::<rooms::short::Service>("rooms::short"),
timeline: args.depend::<rooms::timeline::Service>("rooms::timeline"),
},
services: args.services.clone(),
db: Data::new(&args),
}))
}

View File

@@ -14,29 +14,20 @@ use tuwunel_core::{
};
use tuwunel_database::{Map, keyval::Val};
use crate::{
Dep, rooms,
rooms::{
short::ShortRoomId,
timeline::{PduId, RawPduId},
},
use crate::rooms::{
short::ShortRoomId,
timeline::{PduId, RawPduId},
};
pub struct Service {
db: Data,
services: Services,
services: Arc<crate::services::OnceServices>,
}
struct Data {
tokenids: Arc<Map>,
}
struct Services {
short: Dep<rooms::short::Service>,
state_accessor: Dep<rooms::state_accessor::Service>,
timeline: Dep<rooms::timeline::Service>,
}
#[derive(Clone, Debug)]
pub struct RoomQuery<'a> {
pub room_id: &'a RoomId,
@@ -56,12 +47,7 @@ impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
db: Data { tokenids: args.db["tokenids"].clone() },
services: Services {
short: args.depend::<rooms::short::Service>("rooms::short"),
state_accessor: args
.depend::<rooms::state_accessor::Service>("rooms::state_accessor"),
timeline: args.depend::<rooms::timeline::Service>("rooms::timeline"),
},
services: args.services.clone(),
}))
}

View File

@@ -7,11 +7,9 @@ pub use tuwunel_core::matrix::pdu::{ShortEventId, ShortId, ShortRoomId, ShortSta
use tuwunel_core::{Result, err, implement, matrix::StateKey, utils, utils::IterStream};
use tuwunel_database::{Deserialized, Get, Map, Qry};
use crate::{Dep, globals};
pub struct Service {
db: Data,
services: Services,
services: Arc<crate::services::OnceServices>,
}
struct Data {
@@ -23,10 +21,6 @@ struct Data {
statehash_shortstatehash: Arc<Map>,
}
struct Services {
globals: Dep<globals::Service>,
}
pub type ShortStateHash = ShortId;
impl crate::Service for Service {
@@ -40,9 +34,7 @@ impl crate::Service for Service {
roomid_shortroomid: args.db["roomid_shortroomid"].clone(),
statehash_shortstatehash: args.db["statehash_shortstatehash"].clone(),
},
services: Services {
globals: args.depend::<globals::Service>("globals"),
},
services: args.services.clone(),
}))
}

View File

@@ -32,22 +32,12 @@ use tuwunel_core::{
};
pub use self::pagination_token::PaginationToken;
use crate::{Dep, rooms, sending};
pub struct Service {
services: Services,
services: Arc<crate::services::OnceServices>,
pub roomid_spacehierarchy_cache: Mutex<Cache>,
}
struct Services {
state_accessor: Dep<rooms::state_accessor::Service>,
state_cache: Dep<rooms::state_cache::Service>,
state: Dep<rooms::state::Service>,
event_handler: Dep<rooms::event_handler::Service>,
timeline: Dep<rooms::timeline::Service>,
sending: Dep<sending::Service>,
}
pub struct CachedSpaceHierarchySummary {
summary: SpaceHierarchyParentSummary,
}
@@ -74,16 +64,7 @@ impl crate::Service for Service {
let cache_size = f64::from(config.roomid_spacehierarchy_cache_capacity);
let cache_size = cache_size * config.cache_capacity_modifier;
Ok(Arc::new(Self {
services: Services {
state_accessor: args
.depend::<rooms::state_accessor::Service>("rooms::state_accessor"),
state_cache: args.depend::<rooms::state_cache::Service>("rooms::state_cache"),
state: args.depend::<rooms::state::Service>("rooms::state"),
event_handler: args
.depend::<rooms::event_handler::Service>("rooms::event_handler"),
timeline: args.depend::<rooms::timeline::Service>("rooms::timeline"),
sending: args.depend::<sending::Service>("sending"),
},
services: args.services.clone(),
roomid_spacehierarchy_cache: Mutex::new(LruCache::new(usize_from_f64(cache_size)?)),
}))
}

View File

@@ -25,29 +25,19 @@ use tuwunel_core::{
use tuwunel_database::{Deserialized, Ignore, Interfix, Map};
use crate::{
Dep, globals, rooms,
rooms::{
short::{ShortEventId, ShortStateHash, ShortStateKey},
state_compressor::{CompressedState, parse_compressed_state_event},
},
services::OnceServices,
};
pub struct Service {
pub mutex: RoomMutexMap,
services: Services,
services: Arc<OnceServices>,
db: Data,
}
struct Services {
globals: Dep<globals::Service>,
short: Dep<rooms::short::Service>,
spaces: Dep<rooms::spaces::Service>,
state_cache: Dep<rooms::state_cache::Service>,
state_accessor: Dep<rooms::state_accessor::Service>,
state_compressor: Dep<rooms::state_compressor::Service>,
timeline: Dep<rooms::timeline::Service>,
}
struct Data {
shorteventid_shortstatehash: Arc<Map>,
roomid_shortstatehash: Arc<Map>,
@@ -62,17 +52,7 @@ impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
mutex: RoomMutexMap::new(),
services: Services {
globals: args.depend::<globals::Service>("globals"),
short: args.depend::<rooms::short::Service>("rooms::short"),
spaces: args.depend::<rooms::spaces::Service>("rooms::spaces"),
state_cache: args.depend::<rooms::state_cache::Service>("rooms::state_cache"),
state_accessor: args
.depend::<rooms::state_accessor::Service>("rooms::state_accessor"),
state_compressor: args
.depend::<rooms::state_compressor::Service>("rooms::state_compressor"),
timeline: args.depend::<rooms::timeline::Service>("rooms::timeline"),
},
services: args.services.clone(),
db: Data {
shorteventid_shortstatehash: args.db["shorteventid_shortstatehash"].clone(),
roomid_shortstatehash: args.db["roomid_shortstatehash"].clone(),

View File

@@ -33,21 +33,11 @@ use tuwunel_core::{
};
use tuwunel_database::Map;
use crate::{Dep, rooms};
pub struct Service {
services: Services,
services: Arc<crate::services::OnceServices>,
db: Data,
}
struct Services {
short: Dep<rooms::short::Service>,
state: Dep<rooms::state::Service>,
state_compressor: Dep<rooms::state_compressor::Service>,
state_cache: Dep<rooms::state_cache::Service>,
timeline: Dep<rooms::timeline::Service>,
}
struct Data {
shorteventid_shortstatehash: Arc<Map>,
}
@@ -56,14 +46,7 @@ struct Data {
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
services: Services {
state_cache: args.depend::<rooms::state_cache::Service>("rooms::state_cache"),
timeline: args.depend::<rooms::timeline::Service>("rooms::timeline"),
short: args.depend::<rooms::short::Service>("rooms::short"),
state: args.depend::<rooms::state::Service>("rooms::state"),
state_compressor: args
.depend::<rooms::state_compressor::Service>("rooms::state_compressor"),
},
services: args.services.clone(),
db: Data {
shorteventid_shortstatehash: args.db["shorteventid_shortstatehash"].clone(),
},

View File

@@ -20,23 +20,14 @@ use tuwunel_core::{
};
use tuwunel_database::{Deserialized, Ignore, Interfix, Map};
use crate::{Dep, account_data, appservice::RegistrationInfo, config, globals, rooms, users};
use crate::appservice::RegistrationInfo;
pub struct Service {
appservice_in_room_cache: AppServiceInRoomCache,
services: Services,
services: Arc<crate::services::OnceServices>,
db: Data,
}
struct Services {
account_data: Dep<account_data::Service>,
config: Dep<config::Service>,
globals: Dep<globals::Service>,
metadata: Dep<rooms::metadata::Service>,
state_accessor: Dep<rooms::state_accessor::Service>,
users: Dep<users::Service>,
}
struct Data {
roomid_knockedcount: Arc<Map>,
roomid_invitedcount: Arc<Map>,
@@ -63,15 +54,7 @@ impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
appservice_in_room_cache: RwLock::new(HashMap::new()),
services: Services {
account_data: args.depend::<account_data::Service>("account_data"),
config: args.depend::<config::Service>("config"),
globals: args.depend::<globals::Service>("globals"),
metadata: args.depend::<rooms::metadata::Service>("rooms::metadata"),
state_accessor: args
.depend::<rooms::state_accessor::Service>("rooms::state_accessor"),
users: args.depend::<users::Service>("users"),
},
services: args.services.clone(),
db: Data {
roomid_knockedcount: args.db["roomid_knockedcount"].clone(),
roomid_invitedcount: args.db["roomid_invitedcount"].clone(),

View File

@@ -17,20 +17,12 @@ use tuwunel_core::{
};
use tuwunel_database::Map;
use crate::{
Dep, rooms,
rooms::short::{ShortEventId, ShortId, ShortStateHash, ShortStateKey},
};
use crate::rooms::short::{ShortEventId, ShortId, ShortStateHash, ShortStateKey};
pub struct Service {
pub stateinfo_cache: Mutex<StateInfoLruCache>,
db: Data,
services: Services,
}
struct Services {
short: Dep<rooms::short::Service>,
state: Dep<rooms::state::Service>,
services: Arc<crate::services::OnceServices>,
}
struct Data {
@@ -77,10 +69,7 @@ impl crate::Service for Service {
db: Data {
shortstatehash_statediff: args.db["shortstatehash_statediff"].clone(),
},
services: Services {
short: args.depend::<rooms::short::Service>("rooms::short"),
state: args.depend::<rooms::state::Service>("rooms::state"),
},
services: args.services.clone(),
}))
}

View File

@@ -16,16 +16,9 @@ use tuwunel_core::{
};
use tuwunel_database::{Deserialized, Map};
use crate::{Dep, rooms};
pub struct Service {
db: Data,
services: Services,
}
struct Services {
short: Dep<rooms::short::Service>,
timeline: Dep<rooms::timeline::Service>,
services: Arc<crate::services::OnceServices>,
}
pub(super) struct Data {
@@ -38,10 +31,7 @@ impl crate::Service for Service {
db: Data {
threadid_userids: args.db["threadid_userids"].clone(),
},
services: Services {
short: args.depend::<rooms::short::Service>("rooms::short"),
timeline: args.depend::<rooms::timeline::Service>("rooms::timeline"),
},
services: args.services.clone(),
}))
}

View File

@@ -22,7 +22,7 @@ use ruma::{
use serde::Deserialize;
pub use tuwunel_core::matrix::pdu::{PduId, RawPduId};
use tuwunel_core::{
Err, Result, Server, at, err, implement,
Err, Result, at, err, implement,
matrix::pdu::{PduCount, PduEvent},
utils::{
MutexMap, MutexMapGuard,
@@ -33,41 +33,14 @@ use tuwunel_core::{
};
use tuwunel_database::{Database, Deserialized, Json, KeyVal, Map};
use crate::{
Dep, account_data, admin, appservice, globals, pusher, rooms, rooms::short::ShortRoomId,
sending, server_keys, users,
};
use crate::rooms::short::ShortRoomId;
pub struct Service {
services: Services,
services: Arc<crate::services::OnceServices>,
db: Data,
pub mutex_insert: RoomMutexMap,
}
struct Services {
server: Arc<Server>,
account_data: Dep<account_data::Service>,
appservice: Dep<appservice::Service>,
admin: Dep<admin::Service>,
alias: Dep<rooms::alias::Service>,
globals: Dep<globals::Service>,
short: Dep<rooms::short::Service>,
state: Dep<rooms::state::Service>,
state_cache: Dep<rooms::state_cache::Service>,
state_accessor: Dep<rooms::state_accessor::Service>,
pdu_metadata: Dep<rooms::pdu_metadata::Service>,
read_receipt: Dep<rooms::read_receipt::Service>,
sending: Dep<sending::Service>,
server_keys: Dep<server_keys::Service>,
user: Dep<rooms::user::Service>,
users: Dep<users::Service>,
pusher: Dep<pusher::Service>,
threads: Dep<rooms::threads::Service>,
search: Dep<rooms::search::Service>,
spaces: Dep<rooms::spaces::Service>,
event_handler: Dep<rooms::event_handler::Service>,
}
struct Data {
eventid_outlierpdu: Arc<Map>,
eventid_pduid: Arc<Map>,
@@ -107,31 +80,7 @@ pub type PdusIterItem = (PduCount, PduEvent);
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
services: Services {
server: args.server.clone(),
account_data: args.depend::<account_data::Service>("account_data"),
appservice: args.depend::<appservice::Service>("appservice"),
admin: args.depend::<admin::Service>("admin"),
alias: args.depend::<rooms::alias::Service>("rooms::alias"),
globals: args.depend::<globals::Service>("globals"),
short: args.depend::<rooms::short::Service>("rooms::short"),
state: args.depend::<rooms::state::Service>("rooms::state"),
state_cache: args.depend::<rooms::state_cache::Service>("rooms::state_cache"),
state_accessor: args
.depend::<rooms::state_accessor::Service>("rooms::state_accessor"),
pdu_metadata: args.depend::<rooms::pdu_metadata::Service>("rooms::pdu_metadata"),
read_receipt: args.depend::<rooms::read_receipt::Service>("rooms::read_receipt"),
sending: args.depend::<sending::Service>("sending"),
server_keys: args.depend::<server_keys::Service>("server_keys"),
user: args.depend::<rooms::user::Service>("rooms::user"),
users: args.depend::<users::Service>("users"),
pusher: args.depend::<pusher::Service>("pusher"),
threads: args.depend::<rooms::threads::Service>("rooms::threads"),
search: args.depend::<rooms::search::Service>("rooms::search"),
spaces: args.depend::<rooms::spaces::Service>("rooms::spaces"),
event_handler: args
.depend::<rooms::event_handler::Service>("rooms::event_handler"),
},
services: args.services.clone(),
db: Data {
eventid_outlierpdu: args.db["eventid_outlierpdu"].clone(),
eventid_pduid: args.db["eventid_pduid"].clone(),

View File

@@ -11,11 +11,11 @@ use tuwunel_core::{
utils::{self, IterStream},
};
use crate::{Dep, globals, sending, sending::EduBuf, users};
use crate::sending::EduBuf;
pub struct Service {
server: Arc<Server>,
services: Services,
services: Arc<crate::services::OnceServices>,
/// u64 is unix timestamp of timeout
pub typing: RwLock<BTreeMap<OwnedRoomId, BTreeMap<OwnedUserId, u64>>>,
/// timestamp of the last change to typing users
@@ -23,21 +23,11 @@ pub struct Service {
pub typing_update_sender: broadcast::Sender<OwnedRoomId>,
}
struct Services {
globals: Dep<globals::Service>,
sending: Dep<sending::Service>,
users: Dep<users::Service>,
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
server: args.server.clone(),
services: Services {
globals: args.depend::<globals::Service>("globals"),
sending: args.depend::<sending::Service>("sending"),
users: args.depend::<users::Service>("users"),
},
services: args.services.clone(),
typing: RwLock::new(BTreeMap::new()),
last_typing_update: RwLock::new(BTreeMap::new()),
typing_update_sender: broadcast::channel(100).0,

View File

@@ -4,11 +4,11 @@ use ruma::{RoomId, UserId};
use tuwunel_core::{Result, implement};
use tuwunel_database::{Database, Deserialized, Map};
use crate::{Dep, globals, rooms, rooms::short::ShortStateHash};
use crate::rooms::short::ShortStateHash;
pub struct Service {
db: Data,
services: Services,
services: Arc<crate::services::OnceServices>,
}
struct Data {
@@ -19,11 +19,6 @@ struct Data {
roomsynctoken_shortstatehash: Arc<Map>,
}
struct Services {
globals: Dep<globals::Service>,
short: Dep<rooms::short::Service>,
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
@@ -34,11 +29,7 @@ impl crate::Service for Service {
roomuserid_lastnotificationread: args.db["userroomid_highlightcount"].clone(),
roomsynctoken_shortstatehash: args.db["roomsynctoken_shortstatehash"].clone(),
},
services: Services {
globals: args.depend::<globals::Service>("globals"),
short: args.depend::<rooms::short::Service>("rooms::short"),
},
services: args.services.clone(),
}))
}