Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@1yam
Copy link
Member

@1yam 1yam commented Dec 15, 2025

This Pr goal is to make a new endpoints /api/v1/addresses/stats.json to handle address stats with filter, pagination

Related Clickup or Jira tickets : ALEPH-XXX

Self proofreading checklist

  • Is my code clear enough and well documented
  • Are my files well typed
  • New translations have been added or updated if new strings have been introduced in the frontend
  • Database migrations file are included
  • Are there enough tests
  • Documentation has been included (for new feature)

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:

  • Added a new Alembic migration to create the address_total_message_stats materialized view, which aggregates total message counts per address and includes indexes (including a trigram index) to support fast substring search and efficient sorting/filtering.
  • Updated the backend logic in messages.py to:
    • Add fetch_stats_for_addresses for advanced address stats queries with filtering, sorting, and pagination.
    • Add find_matching_addresses for fast substring search using the new trigram index.
    • Ensure materialized views are refreshed together for up-to-date stats.

API and Schema Enhancements:

  • Introduced the AddressesQueryParams schema, supporting flexible query parameters for filtering, sorting, and pagination of address statistics, including substring search.
  • Added a new API endpoint /api/v1/addresses/stats.json with the addresses_stats_view_v2 handler, which leverages the new backend logic and schema for efficient address stats queries. [1] [2]

Testing:

  • Added comprehensive tests for address stats functions, covering substring search, filtering, sorting, and pagination to ensure correctness and robustness of the new querying system.

Copilot AI review requested due to automatic review settings December 15, 2025 14:05
Copy link

Copilot AI left a 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_stats with 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.

Copy link
Member

@nesitor nesitor left a 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.

Copy link
Member

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.

Copy link

Copilot AI left a 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.

)

# Pagination
if per_page: # Do we want to return all matching result if requested ?
Copy link

Copilot AI Dec 17, 2025

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.

Copilot uses AI. Check for mistakes.
@1yam 1yam force-pushed the 1yam-address-improvment branch from d2ab60a to d07f760 Compare December 22, 2025 09:31
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