Skip to content

Comments

refactor: service card and opening times optimisation#250

Merged
james-cross merged 1 commit intostagingfrom
refactor/services-api-facet-optimisation
Feb 18, 2026
Merged

refactor: service card and opening times optimisation#250
james-cross merged 1 commit intostagingfrom
refactor/services-api-facet-optimisation

Conversation

@james-cross
Copy link
Collaborator

Summary

Extracts shared components and utilities from duplicated code across ServiceCard, GroupedServiceCard, and OrganisationServicesAccordion. Moves per-render work to data processing time where possible.

Part of the services API and rendering optimisation series (chunks 02-04).

Changes

  • Extract OpeningTimesList component and formatOpeningTimes utility from duplicated opening times IIFEs in ServiceCard and OrganisationServicesAccordion
  • Extract VerifiedBadge component from duplicated inline SVG in ServiceCard and GroupedServiceCard
  • Extract buildOrganisationUrl utility from duplicated URL construction in both card components
  • Simplify opening times cache key to use service ID only (TTL check already handles expiry individually, minute-based key caused batch invalidation)
  • Split ServiceCard useMemo into service-specific ([service]) and URL-specific ([slug, location, searchParams]) memos
  • Move appointment-only keyword detection from isServiceOpenNow (per-render) to processServiceData (once per service)
  • Pre-decode text (decodeText) in processServiceData instead of per-render in cards
  • Skip LazyMarkdownContent for plain text descriptions (render <p> instead)
  • Merge services count query into single $facet pipeline (previous commit)
  • Centralise config constants, cache headers, and env vars (previous commit)

Testing

  • All 463 passing unit tests continue to pass (3 flaky sitemap tests are pre-existing and environment-dependent)
  • Updated openingTimes tests to reflect appointment-only detection architecture change
  • TypeScript type check passes with no errors
  • ESLint passes with no warnings
  • Next.js production build succeeds
  • New components (OpeningTimesList, VerifiedBadge) covered by existing ServiceCard and accordion tests

- Extract OpeningTimesList component and formatOpeningTimes utility from duplicated IIFEs in ServiceCard and OrganisationServicesAccordion
- Extract VerifiedBadge component from duplicated SVG in ServiceCard and GroupedServiceCard
- Extract buildOrganisationUrl utility from duplicated URL construction logic
- Simplify opening times cache key to avoid batch invalidation of all entries
- Split ServiceCard useMemo into service-specific and URL-specific memos
- Move appointment-only keyword detection to processServiceData (runs once per service)
- Pre-decode text in processServiceData to avoid per-render decoding
- Skip LazyMarkdownContent for plain text descriptions
@james-cross james-cross merged commit 158762d into staging Feb 18, 2026
6 checks passed
@james-cross james-cross deleted the refactor/services-api-facet-optimisation branch February 18, 2026 22:38
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.

1 participant