Skip to content

fix: improve address fetching#2558

Merged
baktun14 merged 4 commits intomainfrom
fix/adress-reference-fetching
Jan 23, 2026
Merged

fix: improve address fetching#2558
baktun14 merged 4 commits intomainfrom
fix/adress-reference-fetching

Conversation

@baktun14
Copy link
Contributor

@baktun14 baktun14 commented Jan 22, 2026

Summary by CodeRabbit

  • Performance Improvements

    • Added caching to address, block, transaction, and validator endpoints for faster responses.
    • Improved transaction lookup for address queries, enhancing selection, ordering, and pagination behavior.
  • Database & Indexing

    • Added a denormalized height field to address references, backfilled existing values, and created a composite address+height index to accelerate lookups.
    • Indexer now records height on address references to support optimized queries.

✏️ Tip: You can customize this high-level summary in your review settings.

@baktun14 baktun14 requested a review from a team as a code owner January 22, 2026 16:55
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

Adds memoization decorators to several service methods, changes getTransactionsByAddress to positional params and updates its repository SQL to use an INNER JOIN with addressReference, denormalizes/backfills a height column on addressReference with a composite index, updates indexer code and tests to populate and account for height.

Changes

Cohort / File(s) Summary
Service memoization
apps/api/src/address/services/address/address.service.ts, apps/api/src/block/services/akash-block/akash-block.service.ts, apps/api/src/transaction/services/transaction/transaction.service.ts, apps/api/src/validator/services/validator/validator.service.ts
Added Memoize import and applied @Memoize(...) decorators to public methods with TTLs (using averageBlockTime or explicit 60s).
Transaction repository & service signature
apps/api/src/transaction/repositories/transaction/transaction.repository.ts, apps/api/src/transaction/services/transaction/transaction.service.ts, apps/api/src/address/controllers/address/address.controller.ts, apps/api/src/transaction/repositories/transaction/transaction.repository.spec.ts
Changed getTransactionsByAddress signature to positional (address, skip?, limit?); repository SQL rewritten to use INNER JOIN on addressReference, updated GROUP BY/ORDER BY and parameter bindings; call sites/tests updated.
Address service call site
apps/api/src/address/services/address/address.service.ts, apps/api/src/address/controllers/address/address.controller.ts
Updated call to transactionService.getTransactionsByAddress to pass (address, 0, 5); applied memoization to getAddressDetails.
Indexer migration & metadata
apps/indexer/drizzle/0005_add_height_to_address_reference.sql, apps/indexer/drizzle/meta/_journal.json, apps/indexer/drizzle/schema.ts
Added height column to addressReference, backfilled from transaction.height, and created composite index (address ASC, height DESC); migration journal updated.
Indexer code updates
apps/indexer/src/indexers/messageAddressesIndexer.ts
Populates height on address reference records in message handlers (handleMsgSend, handleMsgMultiSend, afterEveryTransaction).
Database model update
packages/database/dbSchemas/base/addressReference.ts
Added optional height?: number column and composite index on address + height to the AddressReference model.
Tests / cache cleanup
apps/api/src/address/services/address/address.service.spec.ts
Added cacheEngine.clearAllKeyInCache() calls to test setup to ensure cache isolation.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Client
  participant AddressSvc as AddressService
  participant TxSvc as TransactionService
  participant Repo as TransactionRepository
  participant DB as Database

  Note over AddressSvc: getAddressDetails is memoized (ttl=averageBlockTime)
  Client->>AddressSvc: GET /address/:addr/details
  AddressSvc->>AddressSvc: check cache
  alt cache hit
    AddressSvc-->>Client: return cached response
  else cache miss
    AddressSvc->>TxSvc: getTransactionsByAddress(address, 0, 5)
    TxSvc->>TxSvc: check cache
    alt tx cache hit
      TxSvc-->>AddressSvc: cached transactions
    else tx cache miss
      TxSvc->>Repo: getTransactionsByAddress(address, skip, limit)
      Repo->>DB: SELECT ... INNER JOIN addressReference ON ... WHERE address = $1 ORDER BY af.height DESC, t.index DESC
      DB-->>Repo: rows
      Repo-->>TxSvc: mapped transactions
      TxSvc-->>TxSvc: store in cache
      TxSvc-->>AddressSvc: transactions
    end
    AddressSvc->>AddressSvc: compose response (include txs)
    AddressSvc-->>Client: response
    AddressSvc-->>AddressSvc: store in cache
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ygrishajev
  • stalniy

Poem

🐇 I hop through code with tiny feet,
Caching carrots make results sweet.
Heights tucked near each address line,
Joins and indexes working fine.
A little hop — responses quick as a beat!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective of the pull request, which focuses on improving address fetching through performance optimizations (caching) and query efficiency enhancements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/api/src/transaction/services/transaction/transaction.service.ts`:
- Around line 22-25: The Memoize decorator is generating identical keys because
getTransactionsByAddress receives a single object argument which is filtered
out; fix by changing the method signature to accept primitive args (e.g., async
getTransactionsByAddress(address: string, skip?: number, limit?: number) and
update callers to pass address, skip, limit) so Memoize will include them in the
cache key, or alternatively update/replace the Memoize usage on
getTransactionsByAddress to supply a custom cache-key generator that serializes
the object (address, skip, limit) into a stable string before calling
this.transactionRepository.getTransactionsByAddress; locate the method
getTransactionsByAddress in transaction.service and the Memoize decorator usage
to implement one of these two fixes.
🧹 Nitpick comments (1)
apps/api/src/validator/services/validator/validator.service.ts (1)

46-46: Avoid using any type.

The error: any type annotation violates the coding guidelines. Consider using unknown and performing proper type narrowing, or use a more specific error type.

Suggested fix
-    } catch (error: any) {
-      if (error.response?.status === 404) {
+    } catch (error: unknown) {
+      if (error instanceof Error && "response" in error && (error as { response?: { status?: number } }).response?.status === 404) {

Alternatively, if using axios errors:

+import { AxiosError } from "axios";
...
-    } catch (error: any) {
-      if (error.response?.status === 404) {
+    } catch (error) {
+      if (error instanceof AxiosError && error.response?.status === 404) {

As per coding guidelines, never use type any.

@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.44%. Comparing base (48b4e5f) to head (b1a70ad).
⚠️ Report is 14 commits behind head on main.
✅ All tests successful. No failed tests found.

❌ Your project status has failed because the head coverage (79.31%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2558      +/-   ##
==========================================
- Coverage   50.73%   50.44%   -0.29%     
==========================================
  Files        1063     1054       -9     
  Lines       29513    29185     -328     
  Branches     6541     6507      -34     
==========================================
- Hits        14973    14723     -250     
+ Misses      14187    14109      -78     
  Partials      353      353              
Flag Coverage Δ *Carryforward flag
api 79.31% <100.00%> (-0.05%) ⬇️
deploy-web 31.16% <ø> (ø) Carriedforward from 1c20dee
log-collector ?
notifications 87.94% <ø> (ø) Carriedforward from 1c20dee
provider-console 81.48% <ø> (ø) Carriedforward from 1c20dee
provider-proxy 84.35% <ø> (ø) Carriedforward from 1c20dee

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
.../address/controllers/address/address.controller.ts 100.00% <100.00%> (ø)
...pi/src/address/services/address/address.service.ts 73.52% <100.00%> (+0.80%) ⬆️
.../block/services/akash-block/akash-block.service.ts 100.00% <100.00%> (ø)
...repositories/transaction/transaction.repository.ts 94.44% <100.00%> (ø)
...action/services/transaction/transaction.service.ts 91.66% <100.00%> (+11.66%) ⬆️
.../validator/services/validator/validator.service.ts 97.14% <100.00%> (+0.08%) ⬆️

... and 17 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/api/src/transaction/repositories/transaction/transaction.repository.ts (1)

102-123: Potential SQL error when skip or limit is undefined.

The parameters skip and limit are optional (number | undefined). If either is undefined, the raw SQL query will receive undefined as a replacement value, which could cause unexpected behavior or errors (e.g., OFFSET undefined LIMIT undefined).

Consider providing default values:

🔧 Suggested fix
- async getTransactionsByAddress(address: string, skip?: number, limit?: number): Promise<GetAddressTransactionsResponse> {
+ async getTransactionsByAddress(address: string, skip: number = 0, limit: number = 20): Promise<GetAddressTransactionsResponse> {
🤖 Fix all issues with AI agents
In `@apps/api/src/transaction/services/transaction/transaction.service.ts`:
- Around line 23-26: The cache key collision is caused by optional skip/limit
being undefined and omitted from the Memoize key; change the signature of
getTransactionsByAddress to use numeric default sentinels (e.g., skip: number =
-1, limit: number = -1) so both parameters are always numbers and included in
the Memoize key, and when calling
this.transactionRepository.getTransactionsByAddress(map the sentinel -1 back to
undefined if the repository expects optional parameters) — update the function
signature and the forwarding call accordingly (referencing
getTransactionsByAddress and the Memoize decorator).

@baktun14 baktun14 merged commit 5f7a629 into main Jan 23, 2026
67 of 68 checks passed
@baktun14 baktun14 deleted the fix/adress-reference-fetching branch January 23, 2026 16:23
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.

1 participant

Comments