Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,38 @@ In local testing on 16 October 2026, using PostgreSQL 16 and 100,000 generated a

The first three timings are SQL queries; the last is a GraphQL HTTP response. These results were measured locally, not on the VM, and may differ on other hardware.

#### Prefix search (#55)

Prefix search allows partial words to match album titles and artists, e.g. `radio` matches Radiohead. It uses the existing PostgreSQL GIN index and treats each search term as a prefix, requiring all terms to match.

Performance was tested locally with 100,000 synthetic albums using PostgreSQL 18.6:

| Search | Matches | Query time |
| ----------------------- | ------: | ---------: |
| `synth` | 100,000 | ~35 ms |
| `synthetic art` | 100,000 | ~53 ms |
| `synthetic album 99999` | 1 | ~1.3 ms |

Broad prefixes can match many albums, increasing the work needed for ranking, counts and facets. All tested prefix queries used the existing GIN index.

Measurements are based on two local runs with cached synthetic data and cover only page queries, not the full GraphQL response or energy consumption.

The read-only benchmark is available in `server/scripts/prefix-search-perf.sql`. PostgreSQL tests can be run by setting `TEST_DATABASE_URL` before running the server tests.

### Sustainability measures

Bærekraft here means design choices we can point at rather than claims, so each one is listed with a number.
We consider sustainability through design choices that reduce unnecessary data transfer, processing and resource use, while acknowledging performance tradeoffs.

| Measure | Why it saves work | Effect |
| ------------------------------- | -------------------------------------------------------- | --------------------------------------------------- |
| Plain CSS, no UI framework | No component-library runtime to download or parse | 0 UI dependencies in the bundle |
| `prefers-color-scheme` | OLED screens draw less power on a dark pixel | Dark theme when the OS asks for it |
| `prefers-reduced-motion` | Animations cost frames and battery | Collapsed to near-zero when the OS asks for it |
| Nothing until Search is pressed | Typing would otherwise cost one request per change | `skipToken` holds the query back, so typing is free |
| `cache-first` fetch policy | A repeated search is already in the cache | 0 requests when the answer is cached |
| Code-split album route | The detail page is not needed to browse search results | Separate 3.73 kB chunk, kept out of the main bundle |
| Bundle budget in CI | CI fails before a dependency quietly doubles the payload | 512 000 bytes per JS chunk |
| Measure | Resource consideration | Effect |
| ------------------------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| Plain CSS, no UI framework | No component-library runtime to download or parse | 0 UI dependencies in the bundle |
| `prefers-color-scheme` | OLED screens draw less power on a dark pixel | Dark theme when the OS asks for it |
| `prefers-reduced-motion` | Animations cost frames and battery | Collapsed to near-zero when the OS asks for it |
| Nothing until Search is pressed | Typing would otherwise cost one request per change | `skipToken` holds the query back, so typing is free |
| `cache-first` fetch policy | A repeated search is already in the cache | 0 requests when the answer is cached |
| Code-split album route | The detail page is not needed to browse search results | Separate 3.73 kB chunk, kept out of the main bundle |
| Bundle budget in CI | CI fails before a dependency quietly doubles the payload | 512 000 bytes per JS chunk |
| Indexed prefix search | Uses the existing GIN index, but broad prefixes require more database processing | Better search flexibility, but potentially higher query costs for broad prefixes |

**Bundle size**, production build measured 21 October 2026:

Expand Down Expand Up @@ -183,7 +202,7 @@ The frontend supports searching by album title or artist, committed on Search or

### Backend search behavior

The API uses PostgreSQL full-text search for album titles and artist names. It supports genre and decade filters, relevance/title/release-year sorting, facet counts and cursor-based pagination. These capabilities are available through GraphQL but are not all exposed in the frontend yet.
The API uses PostgreSQL full-text search for album titles and artist names, with prefix matching to support partial words (e.g. `radi` matches `Radiohead`). It supports genre and decade filters, relevance/title/release-year sorting, facet counts and cursor-based pagination. These capabilities are available through GraphQL but are not all exposed in the frontend yet.

## Try the application

Expand Down
6 changes: 3 additions & 3 deletions client/src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect, vi } from 'vitest';
import { act, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { MockedProvider } from '@apollo/client/testing/react';
import type { MockedResponse } from '@apollo/client/testing';
import type { MockLink } from '@apollo/client/testing';
import { GraphQLError } from 'graphql';
import App from './App.js';
import { SEARCH_ALBUMS } from './api/searchAlbums.js';
Expand All @@ -24,7 +24,7 @@ const album: AlbumSummary = {
function mockSearch(
query: string,
albums: AlbumSummary[] = [album],
): MockedResponse<SearchAlbumsData, SearchAlbumsVariables> {
): MockLink.MockedResponse<SearchAlbumsData, SearchAlbumsVariables> {
return {
request: {
query: SEARCH_ALBUMS,
Expand All @@ -44,7 +44,7 @@ function mockSearch(
}

function renderApp(
mocks: MockedResponse<SearchAlbumsData, SearchAlbumsVariables>[] = [],
mocks: MockLink.MockedResponse<SearchAlbumsData, SearchAlbumsVariables>[] = [],
) {
return render(
<MockedProvider mocks={mocks}>
Expand Down
8 changes: 4 additions & 4 deletions client/src/a11y.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { MockedProvider } from '@apollo/client/testing/react';
import type { MockedResponse } from '@apollo/client/testing';
import type { MockLink } from '@apollo/client/testing';
import { GraphQLError } from 'graphql';
import axe from 'axe-core';

Expand All @@ -27,7 +27,7 @@ const album: AlbumSummary = {
function mockSearch(
query: string,
albums: AlbumSummary[] = [album],
): MockedResponse<SearchAlbumsData, SearchAlbumsVariables> {
): MockLink.MockedResponse<SearchAlbumsData, SearchAlbumsVariables> {
return {
request: {
query: SEARCH_ALBUMS,
Expand All @@ -47,7 +47,7 @@ function mockSearch(
}

function renderApp(
mocks: MockedResponse<SearchAlbumsData, SearchAlbumsVariables>[] = [],
mocks: MockLink.MockedResponse<SearchAlbumsData, SearchAlbumsVariables>[] = [],
) {
return render(
<MockedProvider mocks={mocks}>
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('axe-core on the search page', () => {
});

it('is clean when the search fails', async () => {
const failing: MockedResponse<SearchAlbumsData, SearchAlbumsVariables> = {
const failing: MockLink.MockedResponse<SearchAlbumsData, SearchAlbumsVariables> = {
request: {
query: SEARCH_ALBUMS,
variables: {
Expand Down
Loading