Skip to content

Add index on grants table for grantee_address query performance#731

Merged
raymondjacobson merged 2 commits intorj-granteefrom
copilot/sub-pr-730
Mar 21, 2026
Merged

Add index on grants table for grantee_address query performance#731
raymondjacobson merged 2 commits intorj-granteefrom
copilot/sub-pr-730

Conversation

Copy link
Contributor

Copilot AI commented Mar 19, 2026

The GET /grantees/:address/users endpoint was doing a full table scan on grants — the table only had a primary key on (user_id, txhash, grantee_address) with no usable index for lookups by grantee_address.

Changes

  • ddl/migrations/0191_grants_grantee_address_idx.sql — adds a partial index covering the query's filter and sort columns:

    CREATE INDEX IF NOT EXISTS idx_grants_grantee_address
    ON grants(grantee_address, is_revoked, created_at DESC)
    WHERE is_current = true;

    The WHERE is_current = true predicate keeps the index small; is_revoked covers the boolean filter; created_at DESC supports ORDER BY … LIMIT … OFFSET pagination without a sort step.

  • sql/01_schema.sql — schema snapshot updated to reflect the new index.


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Co-authored-by: rickyrombo <3690498+rickyrombo@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback on indexing for GET /grantees/:address/users endpoint Add index on grants table for grantee_address query performance Mar 19, 2026
Copilot AI requested a review from rickyrombo March 19, 2026 19:48
@raymondjacobson raymondjacobson marked this pull request as ready for review March 21, 2026 00:14
@raymondjacobson raymondjacobson merged commit 674a1fa into rj-grantee Mar 21, 2026
1 check passed
@raymondjacobson raymondjacobson deleted the copilot/sub-pr-730 branch March 21, 2026 00:15
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.

3 participants