perf: add query-aligned indexes for Login model#559
Closed
nishantxscooby wants to merge 10 commits intocertego:developfrom
Closed
perf: add query-aligned indexes for Login model#559nishantxscooby wants to merge 10 commits intocertego:developfrom
nishantxscooby wants to merge 10 commits intocertego:developfrom
Conversation
- Clean up invalid IPs during migration - Add migration test for invalid Login.ip values - Align indexes with real query patterns and ordering - Ensure migration safety and test coverage
Contributor
|
@nishantxscooby please close this PR, since the correct one has been already merged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #494
Problem
Several queries on the
Loginmodel were triggering sequential scans on large datasets, leading to slow response times and increased database CPU usage.This was especially visible in query paths relying on
apply_filters, where results are always ordered by timestamp and filtered by fields such asip,country, andevent_id.Solution
This PR adds database indexes that are explicitly aligned with how queries are executed in the codebase:
timestampto match the defaultorder_by("-timestamp")UPPER(country)to supportcountry__iexactipandevent_idbased on confirmed real usageindexfield, as previously discussedScope
Loginmodel onlyThese changes ensure PostgreSQL can use indexes effectively, avoiding sequential scans and improving query performance on large datasets.