perf(neglible): completely veto Arc from AppState
This commit is contained in:
@@ -4,6 +4,7 @@ use actix_web::{App, HttpServer, web};
|
||||
|
||||
pub mod caches;
|
||||
pub mod services;
|
||||
pub mod static_app_data;
|
||||
|
||||
pub struct AppState {
|
||||
pub args: crate::args::Args,
|
||||
@@ -11,6 +12,9 @@ pub struct AppState {
|
||||
pub cache: caches::AppCache<'static>,
|
||||
}
|
||||
|
||||
/// Type alias to be used just as `data: AppData,` extractor in [`actix_web`] request handlers.
|
||||
pub type AppData = static_app_data::StaticAppDataExtractor<&'static AppState>;
|
||||
|
||||
/// Leaks memory for the sake of not atomic'ing all over.
|
||||
#[expect(clippy::missing_errors_doc)]
|
||||
pub async fn start_app(args: crate::args::Args, config: crate::conf::Config) -> io::Result<()> {
|
||||
@@ -18,10 +22,7 @@ pub async fn start_app(args: crate::args::Args, config: crate::conf::Config) ->
|
||||
|
||||
let config = Box::leak(Box::new(config));
|
||||
|
||||
let cache = caches::AppCache::new(
|
||||
&config.unix.magic_paths,
|
||||
&config.unix.groups,
|
||||
);
|
||||
let cache = caches::AppCache::new(&config.unix.magic_paths, &config.unix.groups);
|
||||
|
||||
let app: &AppState = Box::leak(Box::new(AppState {
|
||||
args,
|
||||
@@ -36,7 +37,7 @@ pub async fn start_app(args: crate::args::Args, config: crate::conf::Config) ->
|
||||
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.app_data(web::Data::new(app))
|
||||
.app_data(app)
|
||||
.service(services::images::make_scope(ws::IMAGES))
|
||||
.default_service(web::to(services::not_found::not_found))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user