-
Notifications
You must be signed in to change notification settings - Fork 21
Feature: v1 endpoints for address stats with pagination and filtering #894
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a new v1 API endpoint /api/v1/addresses/stats.json that provides address statistics with enhanced filtering, sorting, and pagination capabilities. The implementation leverages PostgreSQL materialized views with trigram indexing for efficient substring search.
Key changes:
- Database materialized view
address_total_message_statswith trigram indexing for fast address substring search - New query parameter schema with support for filtering by message type counts, sorting options, and pagination
- Backend functions for fetching address statistics and finding matching addresses
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
deployment/migrations/versions/0040_d6539a42cd51_create_address_summary_view.py |
Creates materialized view for address message counts with trigram index for substring search |
src/aleph/schemas/addresses_query_params.py |
Defines query parameters schema with filtering, sorting, and pagination support |
src/aleph/db/accessors/messages.py |
Adds fetch_stats_for_addresses and find_matching_addresses functions with SQL-based queries |
src/aleph/web/controllers/accounts.py |
Implements new v2 endpoint handler with pagination and custom JSON encoding for Decimal types |
src/aleph/web/controllers/routes.py |
Registers new v1 endpoint route |
tests/db/test_address_stats.py |
Comprehensive test coverage for address stats functions including filtering, sorting, and pagination |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
nesitor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some things done with AI that needs to be done in the proper way following the same patterns we already have and also preventing security issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be careful merging that Pr with the other one from Angel (#891) as he also added a migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 10 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
deployment/migrations/versions/0040_d6539a42cd51_create_address_summary_view.py
Outdated
Show resolved
Hide resolved
| ) | ||
|
|
||
| # Pagination | ||
| if per_page: # Do we want to return all matching result if requested ? |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment '# Do we want to return all matching result if requested ?' seems like an unresolved question. If this is intentional behavior (allowing per_page=0 to return all results), the comment should be revised to state the behavior clearly, or if it's a genuine question, it should be addressed before merging.
…w and address_total_message_stats
d2ab60a to
d07f760
Compare
This Pr goal is to make a new endpoints
/api/v1/addresses/stats.jsonto handle address stats with filter, paginationRelated Clickup or Jira tickets : ALEPH-XXX
Self proofreading checklist
Changes
This pull request introduces a new, efficient, and flexible system for querying address statistics, including a new API endpoint, database materialized views, and backend logic. The main focus is to enable advanced filtering, sorting, and substring search of addresses, along with robust pagination and improved performance. Comprehensive tests are also added to ensure correctness.
The most important changes are:
Database and Backend Infrastructure:
address_total_message_statsmaterialized view, which aggregates total message counts per address and includes indexes (including a trigram index) to support fast substring search and efficient sorting/filtering.messages.pyto:fetch_stats_for_addressesfor advanced address stats queries with filtering, sorting, and pagination.find_matching_addressesfor fast substring search using the new trigram index.API and Schema Enhancements:
AddressesQueryParamsschema, supporting flexible query parameters for filtering, sorting, and pagination of address statistics, including substring search./api/v1/addresses/stats.jsonwith theaddresses_stats_view_v2handler, which leverages the new backend logic and schema for efficient address stats queries. [1] [2]Testing: