Skip to content

feat(backend): add variantCount and includeVariants param to collections endpoint#1224

Merged
fhennig merged 6 commits into
mainfrom
feat/collections-variant-count
May 27, 2026
Merged

feat(backend): add variantCount and includeVariants param to collections endpoint#1224
fhennig merged 6 commits into
mainfrom
feat/collections-variant-count

Conversation

@fhennig
Copy link
Copy Markdown
Contributor

@fhennig fhennig commented May 21, 2026

resolves #1107

Summary

Backend

  • Added variantCount: Int field to the Collection response — always present on all collection endpoints
  • Added includeVariants query parameter (default false) to GET /collections: when false, the variants key is omitted from the response, giving callers a lighter payload for list views
  • GET /collections/{id} is unchanged — always returns the full variant list (plus the new variantCount)
  • POST/PUT responses are unchanged — always include full variants and variantCount

API Example

GET /collections (default, includeVariants=false):

{ "id": 1, "name": "...", "variantCount": 3, "createdAt": "..." }

GET /collections?includeVariants=true:

{ "id": 1, "name": "...", "variantCount": 3, "variants": [...], "createdAt": "..." }

Frontend

  • Split the collectionSchema Zod schema into collectionSummarySchema (no variants, for the list endpoint) and collectionSchema (with required variants, for single-collection/create/update endpoints), with variantCount on both
  • Renamed backendService.getCollectionsgetCollectionSummaries (returns CollectionSummary[]); added getCollections that passes includeVariants=true and returns Collection[]
  • CollectionsOverview now uses getCollectionSummaries and reads variantCount directly instead of variants.length

PR Checklist

  • All necessary documentation has been adapted.
  • The implemented feature is covered by an appropriate test.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboards Ready Ready Preview, Comment May 27, 2026 7:09am

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a lightweight “collection summary” shape to the collections list endpoint by introducing variantCount and an includeVariants query param, and updates the frontend to use counts instead of loading full variant lists for overview pages.

Changes:

  • Backend: add variantCount to Collection and add includeVariants to GET /collections to optionally omit variants.
  • Frontend: split collection Zod schema into summary vs full collection, add getCollectionSummaries, and update overview UI/tests to use variantCount.
  • Tests/mocking: adapt backend and frontend tests + route mockers for the new list-response shape.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
website/src/types/Collection.ts Introduces variantCount and a CollectionSummary schema/type split from full Collection.
website/src/components/collections/overview/CollectionsOverview.tsx Switches overview list to fetch summaries and display variantCount.
website/src/components/collections/overview/CollectionsOverview.browser.spec.tsx Updates UI tests to mock summaries and assert variantCount.
website/src/backendApi/backendService.ts Adds getCollectionSummaries and makes getCollections force includeVariants=true.
website/src/backendApi/backendService.spec.ts Updates service tests to validate summary-fetching behavior.
website/routeMocker.ts Renames mocked backend/astro collections list route to summary variant.
backend/src/test/kotlin/org/genspectrum/dashboardsbackend/controller/CollectionsPutTest.kt Adjusts PUT tests for nullable variants in the shared API model.
backend/src/test/kotlin/org/genspectrum/dashboardsbackend/controller/CollectionsPostTest.kt Adjusts POST tests for nullable variants in the shared API model.
backend/src/test/kotlin/org/genspectrum/dashboardsbackend/controller/CollectionsGetTest.kt Adds coverage for includeVariants behavior and variantCount.
backend/src/test/kotlin/org/genspectrum/dashboardsbackend/controller/CollectionsClient.kt Extends test client with includeVariants query param support.
backend/src/main/kotlin/org/genspectrum/dashboardsbackend/model/collection/CollectionTable.kt Adds variantCount population when mapping entities to API models.
backend/src/main/kotlin/org/genspectrum/dashboardsbackend/model/collection/CollectionModel.kt Implements conditional variant loading vs counting for list endpoint.
backend/src/main/kotlin/org/genspectrum/dashboardsbackend/controller/CollectionsController.kt Adds includeVariants request param to GET /collections.
backend/src/main/kotlin/org/genspectrum/dashboardsbackend/api/Collection.kt Makes variants nullable/omittable and adds variantCount to API model.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread website/src/backendApi/backendService.ts
Comment thread website/src/types/Collection.ts Outdated
Comment thread backend/src/main/kotlin/org/genspectrum/dashboardsbackend/api/Collection.kt Outdated
fhennig and others added 6 commits May 27, 2026 09:08
…llections endpoint

GET /collections now includes variantCount on every response, and accepts
includeVariants=false (default) to omit the full variant list for lighter
list-view requests. GET /collections/{id} always returns variants.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lectionSummary type

- Split collection schema into CollectionSummary (list, no variants) and
  Collection (single/create/update, with variants)
- Rename getCollections -> getCollectionSummaries for the lightweight endpoint;
  add getCollections with includeVariants=true returning full Collection[]
- CollectionsOverview uses getCollectionSummaries and reads variantCount directly

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…udeVariants=false

When variants are not requested, replace the batch fetch of all variant
rows with a single COUNT(*) GROUP BY collection_id query. This avoids
loading variant data (including large JSONB filter_object columns) for
every collection, which was causing >7s response times at scale.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.

"organism": "covid",
"description": "A collection of interesting variants",
"variants": [],
"variantCount": 1,
Comment on lines +184 to 196
test('should GET collection summaries without organism filter', async () => {
backendRouteMocker.mockGetCollectionSummaries([aCollection]);

await expect(backendService.getCollections()).resolves.to.deep.equal([aCollection]);
await expect(backendService.getCollectionSummaries()).resolves.to.deep.equal([aCollection]);
});

test('should GET collections filtered by organism', async () => {
backendRouteMocker.mockGetCollections([aCollection], 'covid');
test('should GET collection summaries filtered by organism', async () => {
backendRouteMocker.mockGetCollectionSummaries([aCollection], 'covid');

await expect(backendService.getCollections({ organism: 'covid' })).resolves.to.deep.equal([aCollection]);
await expect(backendService.getCollectionSummaries({ organism: 'covid' })).resolves.to.deep.equal([
aCollection,
]);
});
assertThat(createdCollection.updatedAt, notNullValue())
assertThat(createdCollection.createdAt, equalTo(createdCollection.updatedAt))
createdCollection.variants.forEach { variant ->
createdCollection.variants!!.forEach { variant ->
Comment on lines 56 to +60
assertThat(updated.name, equalTo("Updated Name"))
assertThat(updated.description, equalTo("Updated Description"))
assertThat(updated.variants.size, equalTo(1))
val firstVariant = updated.variants[0] as Variant.QueryVariant
val resultVariants = updated.variants!!
assertThat(resultVariants.size, equalTo(1))
val firstVariant = resultVariants[0] as Variant.QueryVariant
Copy link
Copy Markdown
Contributor

@fengelniederhammer fengelniederhammer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

@fhennig fhennig merged commit df8e694 into main May 27, 2026
11 checks passed
@fhennig fhennig deleted the feat/collections-variant-count branch May 27, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backend: collections: make it possible to request less information

3 participants