about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr Prins <pjotr.public01@thebird.nl>2026-11-17 12:40:20 +0000
committerPjotr Prins <pjotr.public01@thebird.nl>2026-11-17 12:40:20 +0000
commit1fa28faac92bd206cca46b6987c4973360ddadbe (patch)
tree3eb2ff11ad8004932daf77e6e913a260ade573dd
parentd480e89997eb44c7867756ce2d8716a63fe2feaa (diff)
downloadgenenetwork4-1fa28faac92bd206cca46b6987c4973360ddadbe.tar.gz
datasets/{dataset}/probesets: limit_to / ids_only / names_only
Fifth of the six. 45 101 probesets in HC_M2_0606_P, so this is the listing where
the slim answer matters most: names_only turns a multi-megabyte array of
objects into a list of probe names.

Verified on the deployed build:

  GET /datasets/HC_M2_0606_P/probesets                      45 101 objects, as before
  GET ...?names_only=true&limit_to=1427571_at,NOPE          ["1427571_at"] + note: nope

Two mechanical notes that cost a build each: the handler had no Query
extractor, so it takes crate::listing::ListingParams and needs
axum::extract::Query in scope; and the Found branch built its envelope inline
(Ok(Json(ctx.envelope(...)))), so shaping the rows meant opening the branch into
a block. Read tier: 24 ok, 0 failed.
-rw-r--r--src/routes/datasets.rs39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/routes/datasets.rs b/src/routes/datasets.rs
index 1835b4c..eed7d1c 100644
--- a/src/routes/datasets.rs
+++ b/src/routes/datasets.rs
@@ -107,7 +107,8 @@ fn get_dataset_probesets_result(
 #[utoipa::path(get, path = "/datasets/{dataset}/probesets", summary = "List the expression (ProbeSet) traits belonging to a dataset", params(
     ("dataset" = String, Path, description = "Dataset Name, Name2, FullName, ShortName or numeric Id")
 ), responses(
-    (status = 200, description = "The probesets' ProbeSetXRef/ProbeSet metadata", body = Envelope<Vec<db::ProbeSetInfo>>),
+    (status = 200, description = "The probesets' ProbeSetXRef/ProbeSet metadata; \
+`ids_only`/`names_only` answer one value per probeset instead", body = Envelope<crate::listing::Rows>),
     Unauthorized,
     (status = 403, description = "The dataset isn't public, and the caller isn't authorized for it", body = ApiError),
     (status = 404, description = "No matching dataset", body = ApiError),
@@ -118,8 +119,20 @@ pub async fn dataset_probesets(
     ctx: Ctx,
     Path(dataset): Path<String>,
     token: AuthToken,
-) -> Result<Json<Envelope<Vec<db::ProbeSetInfo>>>, ApiError> {
+    axum::extract::Query(params): axum::extract::Query<crate::listing::ListingParams>,
+) -> Result<Json<Envelope<crate::listing::Rows>>, ApiError> {
     let rid = ctx.request_info();
+    // No listing parameters means the old answer: `Rows::Objects`.
+    let listing = crate::listing::Listing::parse(&params).map_err(|detail| {
+        ApiError::new(
+            StatusCode::UNPROCESSABLE_ENTITY,
+            "invalid_listing",
+            "Invalid listing parameters",
+            detail,
+            "dataset_probesets",
+        )
+        .with_request_id(rid.clone())
+    })?;
     let not_found_name = dataset.clone();
     let auth_server_url = Config::load().auth_server_url.clone();
     tokio::task::spawn_blocking(move || {
@@ -150,8 +163,14 @@ pub async fn dataset_probesets(
         .with_request_id(rid.clone()),
     })
     .and_then(|lookup| match lookup {
-        DatasetProbesetsLookup::Found(_authorized, probesets) => Ok(Json(
-            ctx.envelope(probesets)
+        DatasetProbesetsLookup::Found(_authorized, probesets) => {
+            let rows: Vec<serde_json::Value> = probesets
+                .iter()
+                .map(|probeset| serde_json::to_value(probeset).unwrap_or(serde_json::Value::Null))
+                .collect();
+            let (shaped, missing) = listing.shape(rows, params.limit_to.as_deref());
+            let mut envelope = ctx
+                .envelope(shaped)
                 .with_note(db::LOD_NOTE)
                 .with_next(
                     &format!("/datasets/{}", path_segment(&not_found_name)),
@@ -161,8 +180,16 @@ pub async fn dataset_probesets(
                     &format!("/datasets/{}/probesets/{{probeset}}/values", path_segment(&not_found_name)),
                     "One probeset's value per strain, with the mapping suggestions",
                 )
-                .with_links(crate::suggest::root_links()),
-        )),
+                .with_links(crate::suggest::root_links());
+            if !missing.is_empty() {
+                envelope = envelope.with_note(&format!(
+                    "limit_to named {} value(s) that matched no probeset: {}",
+                    missing.len(),
+                    missing.join(", ")
+                ));
+            }
+            Ok(Json(envelope))
+        }
         DatasetProbesetsLookup::Forbidden => Err(ApiError::new(
             StatusCode::FORBIDDEN,
             "forbidden",