Use Pre-Computed Statistics
Leverage time-series aggregation tables for efficient analytics.
Anti-Patternβ
# BAD: Computing trends from raw events
query GetPriceHistory($termId: String!) {
share_price_changes(
where: { term_id: { _eq: $termId } }
order_by: { created_at: asc }
) {
created_at
old_price
new_price
}
}
# Then computing daily aggregates in application code
Best Practiceβ
# GOOD: Using pre-computed daily statistics
query GetDailyPriceStats($termId: String!, $curveId: numeric!) {
share_price_change_stats_daily(
where: {
term_id: { _eq: $termId }
curve_id: { _eq: $curveId }
}
order_by: { bucket: desc }
limit: 30
) {
bucket
first_share_price
last_share_price
difference
change_count
}
}
Available Tablesβ
share_price_change_stats_hourly/daily/weekly/monthlysignal_stats_hourly/daily/monthly
Benefitsβ
- Faster queries: Pre-aggregated data
- Less computation: Done server-side
- Smaller payloads: Aggregated vs raw data
- Better UX: Faster dashboard loading