about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander_Kabui <alexanderkabua@gmail.com>2026-10-06 06:50:07 +0300
committerAlexander_Kabui <alexanderkabua@gmail.com>2026-10-06 06:50:07 +0300
commit42938ea73858ce2a7f99f07c8e06f4face32a51d (patch)
tree6318b9472a03b5d41d1a55f0c545098eb8efc978 /src
parente39356f04c4175634e26d7a98fa3557634bc889c (diff)
downloadgenenetwork4-42938ea73858ce2a7f99f07c8e06f4face32a51d.tar.gz
* src/routes/traits.rs (TraitInfoLookup): box the Found variant.
The Found payload dwarfed the three empty variants, so every
lookup paid the size of a full TraitInfoResponse. Boxing shrinks
the enum; the handler derefs once at the Json boundary.
Diffstat (limited to 'src')
-rw-r--r--src/routes/traits.rs247
1 files changed, 128 insertions, 119 deletions
diff --git a/src/routes/traits.rs b/src/routes/traits.rs
index 880d60d..fea6eb3 100644
--- a/src/routes/traits.rs
+++ b/src/routes/traits.rs
@@ -12,9 +12,9 @@
 //! this -- this is an additional, category-spanning way to reach the
 //! same underlying data, not a replacement.
 
-use axum::Json;
 use axum::extract::{Extension, Path};
 use axum::http::StatusCode;
+use axum::Json;
 use serde::Serialize;
 use tower_http::request_id::RequestId;
 
@@ -79,7 +79,12 @@ fn is_authorised(
             trait_name,
             VIEW_RESOURCE_PRIVILEGE,
         ),
-        None => auth::authorise_dataset(auth_server_url, token, dataset_name, VIEW_RESOURCE_PRIVILEGE),
+        None => auth::authorise_dataset(
+            auth_server_url,
+            token,
+            dataset_name,
+            VIEW_RESOURCE_PRIVILEGE,
+        ),
     }
 }
 
@@ -219,7 +224,7 @@ enum TraitInfoLookup {
     DatasetNotFound,
     TraitNotFound,
     Forbidden,
-    Found(TraitInfoResponse),
+    Found(Box<TraitInfoResponse>),
 }
 
 fn get_trait_info_result(
@@ -251,7 +256,9 @@ fn get_trait_info_result(
             if !authorised {
                 return Ok(TraitInfoLookup::Forbidden);
             }
-            Ok(TraitInfoLookup::Found(TraitInfoResponse::Probeset(info)))
+            Ok(TraitInfoLookup::Found(Box::new(
+                TraitInfoResponse::Probeset(info),
+            )))
         }
         db::TraitDataset::Publish(pf) => {
             let Ok(trait_id) = trait_name.parse::<u32>() else {
@@ -274,7 +281,9 @@ fn get_trait_info_result(
             if !authorised {
                 return Ok(TraitInfoLookup::Forbidden);
             }
-            Ok(TraitInfoLookup::Found(TraitInfoResponse::Publish(info)))
+            Ok(TraitInfoLookup::Found(Box::new(
+                TraitInfoResponse::Publish(info),
+            )))
         }
     }
 }
@@ -303,64 +312,64 @@ pub async fn trait_info(
         get_trait_info_result(&dataset, &trait_name, &auth_server_url, &token)
     })
     .await
-        .map_err(|e| {
-            ApiError::new(
-                StatusCode::INTERNAL_SERVER_ERROR,
-                "internal_error",
-                "Internal error",
-                e.to_string(),
-                "trait_info",
-            )
-            .with_request_id(rid.clone())
-        })?
-        .map_err(|e| match e {
-            TraitAuthError::Db(e) => ApiError::new(
-                StatusCode::INTERNAL_SERVER_ERROR,
-                "database_error",
-                "Database error",
-                e.to_string(),
-                "trait_info",
-            )
-            .with_request_id(rid.clone()),
-            TraitAuthError::Auth(e) => ApiError::new(
-                StatusCode::BAD_GATEWAY,
-                "auth_server_error",
-                "Could not check authorization",
-                e,
-                "trait_info",
-            )
-            .with_request_id(rid.clone()),
-        })
-        .and_then(|lookup| match lookup {
-            TraitInfoLookup::Found(info) => Ok(Json(info)),
-            TraitInfoLookup::Forbidden => Err(ApiError::new(
-                StatusCode::FORBIDDEN,
-                "forbidden",
-                "Not authorized",
-                format!(
-                    "'{not_found_trait}' in dataset '{not_found_dataset}' is not public, \
+    .map_err(|e| {
+        ApiError::new(
+            StatusCode::INTERNAL_SERVER_ERROR,
+            "internal_error",
+            "Internal error",
+            e.to_string(),
+            "trait_info",
+        )
+        .with_request_id(rid.clone())
+    })?
+    .map_err(|e| match e {
+        TraitAuthError::Db(e) => ApiError::new(
+            StatusCode::INTERNAL_SERVER_ERROR,
+            "database_error",
+            "Database error",
+            e.to_string(),
+            "trait_info",
+        )
+        .with_request_id(rid.clone()),
+        TraitAuthError::Auth(e) => ApiError::new(
+            StatusCode::BAD_GATEWAY,
+            "auth_server_error",
+            "Could not check authorization",
+            e,
+            "trait_info",
+        )
+        .with_request_id(rid.clone()),
+    })
+    .and_then(|lookup| match lookup {
+        TraitInfoLookup::Found(info) => Ok(Json(*info)),
+        TraitInfoLookup::Forbidden => Err(ApiError::new(
+            StatusCode::FORBIDDEN,
+            "forbidden",
+            "Not authorized",
+            format!(
+                "'{not_found_trait}' in dataset '{not_found_dataset}' is not public, \
                      and you are not authorized to view it."
-                ),
-                "trait_info",
-            )
-            .with_request_id(rid.clone())),
-            TraitInfoLookup::DatasetNotFound => Err(ApiError::new(
-                StatusCode::NOT_FOUND,
-                "dataset_not_found",
-                "Dataset not found",
-                format!("No dataset matching '{not_found_dataset}'."),
-                "trait_info",
-            )
-            .with_request_id(rid.clone())),
-            TraitInfoLookup::TraitNotFound => Err(ApiError::new(
-                StatusCode::NOT_FOUND,
-                "trait_not_found",
-                "Trait not found",
-                format!("No trait '{not_found_trait}' in dataset '{not_found_dataset}'."),
-                "trait_info",
-            )
-            .with_request_id(rid)),
-        })
+            ),
+            "trait_info",
+        )
+        .with_request_id(rid.clone())),
+        TraitInfoLookup::DatasetNotFound => Err(ApiError::new(
+            StatusCode::NOT_FOUND,
+            "dataset_not_found",
+            "Dataset not found",
+            format!("No dataset matching '{not_found_dataset}'."),
+            "trait_info",
+        )
+        .with_request_id(rid.clone())),
+        TraitInfoLookup::TraitNotFound => Err(ApiError::new(
+            StatusCode::NOT_FOUND,
+            "trait_not_found",
+            "Trait not found",
+            format!("No trait '{not_found_trait}' in dataset '{not_found_dataset}'."),
+            "trait_info",
+        )
+        .with_request_id(rid)),
+    })
 }
 
 enum TraitValuesLookup {
@@ -459,62 +468,62 @@ pub async fn trait_values(
         get_trait_values_result(&dataset, &trait_name, &auth_server_url, &token)
     })
     .await
-        .map_err(|e| {
-            ApiError::new(
-                StatusCode::INTERNAL_SERVER_ERROR,
-                "internal_error",
-                "Internal error",
-                e.to_string(),
-                "trait_values",
-            )
-            .with_request_id(rid.clone())
-        })?
-        .map_err(|e| match e {
-            TraitAuthError::Db(e) => ApiError::new(
-                StatusCode::INTERNAL_SERVER_ERROR,
-                "database_error",
-                "Database error",
-                e.to_string(),
-                "trait_values",
-            )
-            .with_request_id(rid.clone()),
-            TraitAuthError::Auth(e) => ApiError::new(
-                StatusCode::BAD_GATEWAY,
-                "auth_server_error",
-                "Could not check authorization",
-                e,
-                "trait_values",
-            )
-            .with_request_id(rid.clone()),
-        })
-        .and_then(|lookup| match lookup {
-            TraitValuesLookup::Found(values) => Ok(Json(values)),
-            TraitValuesLookup::Forbidden => Err(ApiError::new(
-                StatusCode::FORBIDDEN,
-                "forbidden",
-                "Not authorized",
-                format!(
-                    "'{not_found_trait}' in dataset '{not_found_dataset}' is not public, \
+    .map_err(|e| {
+        ApiError::new(
+            StatusCode::INTERNAL_SERVER_ERROR,
+            "internal_error",
+            "Internal error",
+            e.to_string(),
+            "trait_values",
+        )
+        .with_request_id(rid.clone())
+    })?
+    .map_err(|e| match e {
+        TraitAuthError::Db(e) => ApiError::new(
+            StatusCode::INTERNAL_SERVER_ERROR,
+            "database_error",
+            "Database error",
+            e.to_string(),
+            "trait_values",
+        )
+        .with_request_id(rid.clone()),
+        TraitAuthError::Auth(e) => ApiError::new(
+            StatusCode::BAD_GATEWAY,
+            "auth_server_error",
+            "Could not check authorization",
+            e,
+            "trait_values",
+        )
+        .with_request_id(rid.clone()),
+    })
+    .and_then(|lookup| match lookup {
+        TraitValuesLookup::Found(values) => Ok(Json(values)),
+        TraitValuesLookup::Forbidden => Err(ApiError::new(
+            StatusCode::FORBIDDEN,
+            "forbidden",
+            "Not authorized",
+            format!(
+                "'{not_found_trait}' in dataset '{not_found_dataset}' is not public, \
                      and you are not authorized to view it."
-                ),
-                "trait_values",
-            )
-            .with_request_id(rid.clone())),
-            TraitValuesLookup::DatasetNotFound => Err(ApiError::new(
-                StatusCode::NOT_FOUND,
-                "dataset_not_found",
-                "Dataset not found",
-                format!("No dataset matching '{not_found_dataset}'."),
-                "trait_values",
-            )
-            .with_request_id(rid.clone())),
-            TraitValuesLookup::TraitNotFound => Err(ApiError::new(
-                StatusCode::NOT_FOUND,
-                "trait_not_found",
-                "Trait not found",
-                format!("No trait '{not_found_trait}' in dataset '{not_found_dataset}'."),
-                "trait_values",
-            )
-            .with_request_id(rid)),
-        })
+            ),
+            "trait_values",
+        )
+        .with_request_id(rid.clone())),
+        TraitValuesLookup::DatasetNotFound => Err(ApiError::new(
+            StatusCode::NOT_FOUND,
+            "dataset_not_found",
+            "Dataset not found",
+            format!("No dataset matching '{not_found_dataset}'."),
+            "trait_values",
+        )
+        .with_request_id(rid.clone())),
+        TraitValuesLookup::TraitNotFound => Err(ApiError::new(
+            StatusCode::NOT_FOUND,
+            "trait_not_found",
+            "Trait not found",
+            format!("No trait '{not_found_trait}' in dataset '{not_found_dataset}'."),
+            "trait_values",
+        )
+        .with_request_id(rid)),
+    })
 }