Skip to content

Conversation

@anth-volk
Copy link
Contributor

Fixes #49

Summary

  • Add database indexes to parameter_values table for query optimization
  • Add response caching (1 hour TTL) to the /parameter-values/ endpoint

Changes

Database Migration (supabase/migrations/20251229000000_add_parameter_values_indexes.sql)

Creates 4 indexes:

  • Composite index on (parameter_id, policy_id) for combined filtering
  • Single index on policy_id for policy-only queries
  • Partial index on parameter_id WHERE policy_id IS NULL for baseline value lookups
  • Index on start_date for time-range queries

Caching (src/policyengine_api/api/parameter_values.py)

Added @cache(expire=3600) decorator to list_parameter_values, matching the pattern used in variables.py.

Test plan

  • All 9 tests in test_parameters.py pass
  • Linter passes
  • After deploy, verify indexes are used with EXPLAIN ANALYZE
  • Benchmark endpoint response time

🤖 Generated with Claude Code

@nikhilwoodruff nikhilwoodruff merged commit 7c545d2 into main Dec 29, 2025
1 check passed
@nikhilwoodruff nikhilwoodruff deleted the feat/param-values-indexing branch December 30, 2025 13:18
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.

Add indexing to parameter-value handlers

3 participants