pass args by ref

This commit is contained in:
dasha_uwu
2025-09-17 14:21:55 +05:00
committed by Jason Volk
parent d6e95c51c0
commit 9c4d376bec
43 changed files with 97 additions and 101 deletions

View File

@@ -27,7 +27,7 @@ struct Data {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
services: args.services.clone(),
db: Data {

View File

@@ -63,14 +63,14 @@ const COMMAND_QUEUE_LIMIT: usize = 512;
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
services: args.services.clone(),
channel: StdRwLock::new(None),
handle: RwLock::new(None),
complete: StdRwLock::new(None),
#[cfg(feature = "console")]
console: console::Console::new(&args),
console: console::Console::new(args),
}))
}

View File

@@ -30,7 +30,7 @@ type Registrations = BTreeMap<String, RegistrationInfo>;
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
registration_info: RwLock::new(BTreeMap::new()),
services: args.services.clone(),

View File

@@ -26,7 +26,7 @@ pub struct Service {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
let config = &args.server.config;
macro_rules! create_client {

View File

@@ -15,7 +15,7 @@ const SIGNAL: &str = "SIGUSR1";
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self { server: args.server.clone() }))
}

View File

@@ -12,7 +12,7 @@ pub struct Service {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self { services: args.services.clone() }))
}

View File

@@ -15,7 +15,7 @@ pub struct Service {
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self { services: args.services.clone() }))
}

View File

@@ -12,7 +12,7 @@ pub struct Service {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self { services: args.services.clone() }))
}

View File

@@ -33,8 +33,8 @@ type RateLimitState = (Instant, u32); // Time if last failed try, number of fail
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
let db = Data::new(&args);
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
let db = Data::new(args);
let config = &args.server.config;
let turn_secret = config.turn_secret_file.as_ref().map_or_else(

View File

@@ -24,7 +24,7 @@ struct Data {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
db: Data {
backupid_algorithm: args.db["backupid_algorithm"].clone(),

View File

@@ -47,7 +47,7 @@ pub const CORP_CROSS_ORIGIN: &str = "cross-origin";
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
url_preview_mutex: MutexMap::new(),
db: Data::new(args.db),

View File

@@ -14,7 +14,7 @@ pub struct Service {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self { services: args.services.clone() }))
}

View File

@@ -26,7 +26,7 @@ type TimerType = (OwnedUserId, Duration);
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
let config = &args.server.config;
let idle_timeout_s = config.presence_idle_timeout_s;
let offline_timeout_s = config.presence_offline_timeout_s;
@@ -35,7 +35,7 @@ impl crate::Service for Service {
timeout_remote_users: config.presence_timeout_remote_users,
idle_timeout: checked!(idle_timeout_s * 1_000)?,
offline_timeout: checked!(offline_timeout_s * 1_000)?,
db: Data::new(&args),
db: Data::new(args),
services: args.services.clone(),
last_sync_seen: RwLock::new(HashMap::new()),
}))

View File

@@ -43,7 +43,7 @@ struct Data {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
db: Data {
senderkey_pusher: args.db["senderkey_pusher"].clone(),

View File

@@ -30,8 +30,8 @@ impl crate::Service for Service {
clippy::cast_sign_loss,
clippy::cast_possible_truncation
)]
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
let cache = Cache::new(&args);
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
let cache = Cache::new(args);
Ok(Arc::new(Self {
cache: cache.clone(),
resolver: Resolver::build(args.server, cache)?,

View File

@@ -28,7 +28,7 @@ struct Data {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
db: Data {
alias_userid: args.db["alias_userid"].clone(),

View File

@@ -31,10 +31,10 @@ pub struct Service {
type Bucket<'a> = BTreeSet<(u64, &'a EventId)>;
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
services: args.services.clone(),
db: Data::new(&args),
db: Data::new(args),
}))
}

View File

@@ -17,7 +17,7 @@ pub struct Service {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self { services: args.services.clone() }))
}

View File

@@ -14,7 +14,7 @@ struct Data {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
db: Data {
publicroomids: args.db["publicroomids"].clone(),

View File

@@ -35,7 +35,7 @@ type RoomMutexMap = MutexMap<OwnedRoomId, ()>;
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
mutex_federation: RoomMutexMap::new(),
services: args.services.clone(),

View File

@@ -43,7 +43,7 @@ pub type Witness = HashSet<OwnedUserId>;
type Key<'a> = (&'a UserId, Option<&'a DeviceId>, &'a RoomId, &'a UserId);
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
db: Data {
lazyloadedids: args.db["lazyloadedids"].clone(),

View File

@@ -24,7 +24,7 @@ struct Data {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
db: Data {
disabledroomids: args.db["disabledroomids"].clone(),

View File

@@ -16,10 +16,10 @@ pub struct Service {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
services: args.services.clone(),
db: Data::new(&args),
db: Data::new(args),
}))
}

View File

@@ -28,10 +28,10 @@ pub struct Service {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
services: args.services.clone(),
db: Data::new(&args),
db: Data::new(args),
}))
}

View File

@@ -45,7 +45,7 @@ const TOKEN_ID_MAX_LEN: usize =
const WORD_MAX_LEN: usize = 50;
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
db: Data { tokenids: args.db["tokenids"].clone() },
services: args.services.clone(),

View File

@@ -24,7 +24,7 @@ struct Data {
pub type ShortStateHash = ShortId;
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
db: Data {
eventid_shorteventid: args.db["eventid_shorteventid"].clone(),

View File

@@ -59,7 +59,7 @@ type Cache = LruCache<OwnedRoomId, Option<CachedSpaceHierarchySummary>>;
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
let config = &args.server.config;
let cache_size = f64::from(config.roomid_spacehierarchy_cache_capacity);
let cache_size = cache_size * config.cache_capacity_modifier;

View File

@@ -51,7 +51,7 @@ pub type RoomMutexGuard = MutexMapGuard<OwnedRoomId, ()>;
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
mutex: RoomMutexMap::new(),
services: args.services.clone(),

View File

@@ -44,7 +44,7 @@ struct Data {
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
services: args.services.clone(),
db: Data {

View File

@@ -52,7 +52,7 @@ type StrippedStateEventItem = (OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>);
type SyncStateEventItem = (OwnedRoomId, Vec<Raw<AnySyncStateEvent>>);
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
appservice_in_room_cache: RwLock::new(HashMap::new()),
services: args.services.clone(),

View File

@@ -60,7 +60,7 @@ pub type CompressedStateEvent = [u8; 2 * size_of::<ShortId>()];
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
let config = &args.server.config;
let cache_capacity =
f64::from(config.stateinfo_cache_capacity) * config.cache_capacity_modifier;

View File

@@ -27,7 +27,7 @@ pub(super) struct Data {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
db: Data {
threadid_userids: args.db["threadid_userids"].clone(),

View File

@@ -79,7 +79,7 @@ pub type PdusIterItem = (PduCount, PduEvent);
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
services: args.services.clone(),
db: Data {

View File

@@ -24,7 +24,7 @@ pub struct Service {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
server: args.server.clone(),
services: args.services.clone(),

View File

@@ -23,7 +23,7 @@ struct Data {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
db: Data {
db: args.db.clone(),

View File

@@ -61,10 +61,10 @@ const EDU_VEC_CAP: usize = 1;
#[async_trait]
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
let num_senders = num_senders(&args);
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
let num_senders = num_senders(args);
Ok(Arc::new(Self {
db: Data::new(&args),
db: Data::new(args),
server: args.server.clone(),
services: args.services.clone(),
channels: (0..num_senders)

View File

@@ -40,7 +40,7 @@ pub type PubKeyMap = PublicKeyMap;
pub type PubKeys = PublicKeySet;
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
let minimum_valid = Duration::from_secs(3600);
let (keypair, verify_keys) = keypair::init(args.db)?;

View File

@@ -14,7 +14,7 @@ pub(crate) trait Service: Any + Send + Sync {
/// service type. Note that it may be called again after a server reload,
/// but the prior instance will have been dropped first. Failure will
/// shutdown the server with an error.
fn build(args: Args<'_>) -> Result<Arc<impl Service>>
fn build(args: &Args<'_>) -> Result<Arc<impl Service>>
where
Self: Sized;

View File

@@ -69,58 +69,54 @@ pub struct Services {
pub async fn build(server: Arc<Server>) -> Result<Arc<Self>> {
let db = Database::open(&server).await?;
let services = Arc::new(OnceServices::default());
macro_rules! build {
($tyname:ty) => {
<$tyname>::build(Args {
db: &db,
server: &server,
services: &services,
})?
};
}
let args = Args {
db: &db,
server: &server,
services: &services,
};
let res = Arc::new(Self {
account_data: build!(account_data::Service),
admin: build!(admin::Service),
appservice: build!(appservice::Service),
resolver: build!(resolver::Service),
client: build!(client::Service),
config: build!(config::Service),
emergency: build!(emergency::Service),
globals: build!(globals::Service),
key_backups: build!(key_backups::Service),
media: build!(media::Service),
presence: build!(presence::Service),
pusher: build!(pusher::Service),
alias: build!(rooms::alias::Service),
auth_chain: build!(rooms::auth_chain::Service),
delete: build!(rooms::delete::Service),
directory: build!(rooms::directory::Service),
event_handler: build!(rooms::event_handler::Service),
lazy_loading: build!(rooms::lazy_loading::Service),
metadata: build!(rooms::metadata::Service),
pdu_metadata: build!(rooms::pdu_metadata::Service),
read_receipt: build!(rooms::read_receipt::Service),
search: build!(rooms::search::Service),
short: build!(rooms::short::Service),
spaces: build!(rooms::spaces::Service),
state: build!(rooms::state::Service),
state_accessor: build!(rooms::state_accessor::Service),
state_cache: build!(rooms::state_cache::Service),
state_compressor: build!(rooms::state_compressor::Service),
threads: build!(rooms::threads::Service),
timeline: build!(rooms::timeline::Service),
typing: build!(rooms::typing::Service),
user: build!(rooms::user::Service),
federation: build!(federation::Service),
sending: build!(sending::Service),
server_keys: build!(server_keys::Service),
sync: build!(sync::Service),
transaction_ids: build!(transaction_ids::Service),
uiaa: build!(uiaa::Service),
users: build!(users::Service),
membership: build!(membership::Service),
deactivate: build!(deactivate::Service),
account_data: account_data::Service::build(&args)?,
admin: admin::Service::build(&args)?,
appservice: appservice::Service::build(&args)?,
resolver: resolver::Service::build(&args)?,
client: client::Service::build(&args)?,
config: config::Service::build(&args)?,
emergency: emergency::Service::build(&args)?,
globals: globals::Service::build(&args)?,
key_backups: key_backups::Service::build(&args)?,
media: media::Service::build(&args)?,
presence: presence::Service::build(&args)?,
pusher: pusher::Service::build(&args)?,
alias: rooms::alias::Service::build(&args)?,
auth_chain: rooms::auth_chain::Service::build(&args)?,
delete: rooms::delete::Service::build(&args)?,
directory: rooms::directory::Service::build(&args)?,
event_handler: rooms::event_handler::Service::build(&args)?,
lazy_loading: rooms::lazy_loading::Service::build(&args)?,
metadata: rooms::metadata::Service::build(&args)?,
pdu_metadata: rooms::pdu_metadata::Service::build(&args)?,
read_receipt: rooms::read_receipt::Service::build(&args)?,
search: rooms::search::Service::build(&args)?,
short: rooms::short::Service::build(&args)?,
spaces: rooms::spaces::Service::build(&args)?,
state: rooms::state::Service::build(&args)?,
state_accessor: rooms::state_accessor::Service::build(&args)?,
state_cache: rooms::state_cache::Service::build(&args)?,
state_compressor: rooms::state_compressor::Service::build(&args)?,
threads: rooms::threads::Service::build(&args)?,
timeline: rooms::timeline::Service::build(&args)?,
typing: rooms::typing::Service::build(&args)?,
user: rooms::user::Service::build(&args)?,
federation: federation::Service::build(&args)?,
sending: sending::Service::build(&args)?,
server_keys: server_keys::Service::build(&args)?,
sync: sync::Service::build(&args)?,
transaction_ids: transaction_ids::Service::build(&args)?,
uiaa: uiaa::Service::build(&args)?,
users: users::Service::build(&args)?,
membership: membership::Service::build(&args)?,
deactivate: deactivate::Service::build(&args)?,
manager: Mutex::new(None),
server,

View File

@@ -51,7 +51,7 @@ pub type ListId = SmallString<[u8; 16]>;
pub type ConnId = SmallString<[u8; 16]>;
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
db: Data {
todeviceid_events: args.db["todeviceid_events"].clone(),

View File

@@ -13,7 +13,7 @@ struct Data {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
db: Data {
userdevicetxnid_response: args.db["userdevicetxnid_response"].clone(),

View File

@@ -32,7 +32,7 @@ type RequestKey = (OwnedUserId, OwnedDeviceId, String);
pub const SESSION_ID_LENGTH: usize = 32;
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
userdevicesessionid_uiaarequest: RwLock::new(RequestMap::new()),
db: Data {

View File

@@ -57,7 +57,7 @@ struct Data {
}
impl crate::Service for Service {
fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
fn build(args: &crate::Args<'_>) -> Result<Arc<Self>> {
Ok(Arc::new(Self {
services: args.services.clone(),
db: Data {