Skip to content

fix(insights): reduce activity aggregation overhead - #7908

Merged
waleedlatif1 merged 2 commits into
stagingfrom
codex/insights-query-performance
Sep 17, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
codex/insights-query-performance

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Aggregate workflow and chat activity separately before combining results, preserving exact member counts and duration averages.
  • Add a concurrent covering index for activity queries and log when analytics fall back to the primary database.
  • Format usage timestamps after aggregation and correct timezone bucketing for UTC ledger timestamps.

Type of Change

  • Bug fix

Testing

82 focused tests passed, including PostgreSQL aggregation, timezone, scope, and pagination regressions. Verified the local app and benchmarked reads and writes with synthetic data. Type checks, lint, API validation, migration safety, and repository audits passed. Tested migration application and replay locally.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Sep 17, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
docs Ready Ready Preview Sep 17, 2026 2:36am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with no outstanding correctness, security, or repository-rule issues identified.

Summary

This PR reduces analytics-query overhead while preserving aggregation accuracy and correct timezone behavior.

  • Pre-aggregates workflow and chat activity separately before combining metrics.
  • Formats usage timestamps after aggregation and applies the repository’s UTC timestamp contract during timezone bucketing.
  • Adds focused PostgreSQL regression coverage to CI.
  • Adds a replay-safe concurrent covering index and records its concurrent construction consistently in the Drizzle schema and snapshot.
  • Logs when analytics reads fall back to the primary database.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  W[Workflow execution logs] --> WA[Aggregate workflow metrics]
  C[Copilot runs] --> CA[Aggregate chat metrics]
  WA --> U[Union aggregate rows]
  CA --> U
  U --> F[Combine counts and averages]
  F --> S[Activity summary and breakdown]
  L[Usage ledger timestamps] --> T[UTC-to-viewer timezone conversion]
  T --> B[Aggregate into calendar buckets]
  B --> O[Format bucket timestamps]
Loading

Reviews (2) · Last reviewed commit: "fix(db): declare activity index as concu..."

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 10 files

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Fix all with cubic | Re-trigger cubic

Comment thread packages/db/schema.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 10 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit f2a89aa into staging Sep 17, 2026
34 checks passed
@waleedlatif1
waleedlatif1 deleted the codex/insights-query-performance branch September 17, 2026 02:40

This branch was successfully deployed

1 active deployment
Preview 0a08f33e Deployed Sep 17, 2026 by vercel[bot]
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