From 0c58ad5611077502c639cb1b3406f476f930c863 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sat, 3 Oct 2026 15:57:54 +0000 Subject: Add GET /groups/{group}/traits/{trait_id}; time DB tests; share pool. * src/db.rs (TraitInfo): New struct. Joins PublishXRef, Phenotype and Publication; LEFT JOIN on the latter two since a handful of PublishXRef rows have no matching row. SQL column aliases are written to match mysql_common's UpperCamelCase conversion exactly, so no field needs a #[mysql(rename = "...")] override. (get_group_trait_info): New function. (pool): New function. mysql::Pool::new eagerly opens its default 10 connections before returning (about 7s against this database); every query function here used to call it per request, paying that cost on every single API call. Builds the Pool once behind a OnceLock>> and shares the cheap, Arc-backed handle from then on (OnceLock::get_or_init can't be used alone since Pool::new is fallible and get_or_try_init is still unstable). (get_all_species, get_species_by_name, get_all_groups, get_group_by_name, get_group_strains, get_group_trait_values, get_group_trait_info): Use it instead of building their own Pool. * src/lib.rs (GroupTraitLookup): Generalize over the found value (was Vec-specific), so group_trait_info can share it with group_trait_values. (get_group_trait_info_result): New function. (group_trait_info): New handler for GET /groups/{group}/traits/{trait_id}. (app): Register it. * tests/common/mod.rs: New file. get() issues a GET against genenetwork4::app() and warns on stderr if it takes over a second -- this is what surfaced the Pool::new cost above. * tests/species.rs, tests/species_by_name.rs, tests/groups.rs, tests/group_by_name.rs, tests/group_strains.rs, tests/group_trait_values.rs: Use tests/common::get instead of building each request by hand. * tests/group_trait_info.rs, test/python/test_group_trait_info.py: New files. * tests/openapi.rs, test/python/test_openapi.py: Check the new path is in the generated spec. * README.md (GET /groups/{group}/traits/{trait_id}): Document it. (Tests): List the new test files; document tests/common::get's timing warnings and how to see them. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01XDDpXvZBQat9uSgDeEMJ8d --- test/python/test_openapi.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/python/test_openapi.py') diff --git a/test/python/test_openapi.py b/test/python/test_openapi.py index 753df4e..3b4b704 100644 --- a/test/python/test_openapi.py +++ b/test/python/test_openapi.py @@ -28,6 +28,7 @@ class OpenApiTest(ServerTestCase): "/groups", "/groups/{group}", "/groups/{group}/strains", + "/groups/{group}/traits/{trait_id}", "/groups/{group}/traits/{trait_id}/values", ): self.assertIn(path, doc["paths"]) -- cgit 1.4.1