Skip to content

Archive 1 #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed

Conversation

asafchen-dig
Copy link

@asafchen-dig asafchen-dig commented May 30, 2025

This PR addresses a severe performance degradation in the activity logs query system by fixing an N+1 query pattern.

Problem

The current implementation executes the same query multiple times in a loop, leading to:

  • Query duration: 2.72 seconds (normal: 3.09 milliseconds)
  • Query being executed 82 times per request in 41% of requests
  • Significant performance overhead

Changes

  1. Replaced multiple individual queries with a single optimized query
  2. Implemented pagination to limit result set size
  3. Added proper response structure with pagination metadata
  4. Added OpenTelemetry instrumentation for better observability

Testing

The changes have been tested with:

  • Various page sizes
  • Different numeric value filters
  • Performance measurements showing significant improvement

Performance Impact

  • Expected query duration reduction from 2.72s to ~10ms
  • Elimination of N+1 query pattern
  • Reduced database load
  • Better resource utilization

Fixes #73

@doppleware doppleware changed the title Fix N+1 Query Performance Issue in Activity Logs Query -created-by-agentic Archive 1 May 31, 2025
@doppleware doppleware closed this May 31, 2025
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.

Performance Issue: N+1 Query Pattern in Activity Logs Query -created-by-agentic
2 participants