Skip to content

refactor(dx): replace loadWithPagination with getAllItems#2942

Open
stalniy wants to merge 1 commit intomainfrom
refactor/dx-replace-loadWithPagination
Open

refactor(dx): replace loadWithPagination with getAllItems#2942
stalniy wants to merge 1 commit intomainfrom
refactor/dx-replace-loadWithPagination

Conversation

@stalniy
Copy link
Copy Markdown
Contributor

@stalniy stalniy commented Mar 17, 2026

Why

  • loadWithPagination is deprecated in favor of getAllItems from @akashnetwork/http-sdk
  • getAllItems includes circular loop detection, preventing infinite pagination loops
  • Consolidates pagination logic into a single, well-tested utility

What

  • Replaced all usages of loadWithPagination with getAllItems from @akashnetwork/http-sdk in:
    • apps/deploy-web/src/queries/useDeploymentQuery.ts
    • apps/deploy-web/src/queries/useGrantsQuery.ts
    • apps/deploy-web/src/queries/useLeaseQuery.ts
    • apps/deploy-web/src/services/wallet-balances/wallet-balances.service.ts
    • packages/http-sdk/src/deployment/deployment-http.service.ts
  • Removed deprecated loadWithPagination and hasQueryParam from:
    • apps/deploy-web/src/utils/apiUtils.ts
    • packages/http-sdk/src/utils/pagination.utils.ts
  • Removed dead loadWithPagination code from apps/indexer/src/shared/utils/query.ts
  • Updated test assertions to match the new axios params-based API call pattern

Summary by CodeRabbit

Release Notes

  • Refactor
    • Modernized internal data-fetching mechanism across deployment, lease, and balance queries for improved efficiency.
    • Removed deprecated pagination utilities and streamlined query handling.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

A migration from the deprecated loadWithPagination utility to getAllItems across multiple packages and services. The removal of loadWithPagination from shared utilities and updates to dependent query hooks, services, and tests to use the new callback-based pagination approach.

Changes

Cohort / File(s) Summary
Pagination Utility Removal
apps/deploy-web/src/utils/apiUtils.ts, packages/http-sdk/src/utils/pagination.utils.ts, apps/indexer/src/shared/utils/query.ts
Removed deprecated loadWithPagination function and related helpers (hasQueryParam). Pagination logic now centralized through getAllItems callback pattern.
Deploy Web Query Migrations
apps/deploy-web/src/queries/useDeploymentQuery.ts, apps/deploy-web/src/queries/useGrantsQuery.ts, apps/deploy-web/src/queries/useLeaseQuery.ts
Replaced loadWithPagination with getAllItems for deployment, grants, and lease list fetching. Updated to use direct Axios calls with pagination.limit: 1000 and callback-based result mapping.
Deploy Web Query Tests
apps/deploy-web/src/queries/useGrantsQuery.spec.tsx, apps/deploy-web/src/queries/useLeaseQuery.spec.tsx
Updated test assertions to match new chainApiHttpClient.get call signatures that now include request parameters as second argument.
Service Layer Migrations
apps/deploy-web/src/services/wallet-balances/wallet-balances.service.ts
Migrated wallet balances deployment fetch from loadWithPagination to getAllItems with callback-based pagination aggregation.
HTTP SDK Pagination Update
packages/http-sdk/src/deployment/deployment-http.service.ts
Updated findAll method to use getAllItems instead of loadWithPagination when pagination argument is absent, maintaining existing return shape.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 The pagination hops to a new beat,
\getAllItems\\ makes the refactor complete!
Old loops fade as callbacks take flight,
Through deploy and indexer, shining bright.
A tidy migration, efficient and neat! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% 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
Title check ✅ Passed The title 'refactor(dx): replace loadWithPagination with getAllItems' clearly and concisely summarizes the primary change in the PR, which is replacing the deprecated pagination utility with a newer alternative across multiple files.
Description check ✅ Passed The PR description follows the template structure with well-articulated 'Why' (motivation with specific benefits) and 'What' (detailed list of changes) sections covering all modifications made.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/dx-replace-loadWithPagination

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

@stalniy stalniy force-pushed the refactor/dx-replace-loadWithPagination branch 2 times, most recently from 8a64763 to 0057fbc Compare March 17, 2026 12:56
@github-actions github-actions Bot added size: S and removed size: M labels Mar 17, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 82.35294% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.28%. Comparing base (db24592) to head (7c64738).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
apps/deploy-web/src/queries/useDeploymentQuery.ts 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2942      +/-   ##
==========================================
- Coverage   60.92%   60.28%   -0.64%     
==========================================
  Files        1023     1009      -14     
  Lines       24479    23866     -613     
  Branches     6057     5940     -117     
==========================================
- Hits        14913    14388     -525     
+ Misses       8354     8275      -79     
+ Partials     1212     1203       -9     
Flag Coverage Δ *Carryforward flag
api 82.61% <ø> (+0.02%) ⬆️
deploy-web 44.81% <82.35%> (-0.04%) ⬇️
log-collector ?
notifications 86.06% <ø> (ø)
provider-console 81.48% <ø> (ø) Carriedforward from db24592
provider-proxy 85.21% <ø> (ø) Carriedforward from db24592
tx-signer 76.26% <ø> (ø)

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

Files with missing lines Coverage Δ
apps/deploy-web/src/queries/useGrantsQuery.ts 100.00% <100.00%> (ø)
apps/deploy-web/src/queries/useLeaseQuery.ts 95.65% <100.00%> (+0.19%) ⬆️
...ervices/wallet-balances/wallet-balances.service.ts 82.35% <100.00%> (+1.70%) ⬆️
apps/deploy-web/src/utils/apiUtils.ts 63.09% <ø> (-4.59%) ⬇️
apps/deploy-web/src/queries/useDeploymentQuery.ts 33.33% <0.00%> (-4.17%) ⬇️

... and 15 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.

@stalniy stalniy force-pushed the refactor/dx-replace-loadWithPagination branch from 0057fbc to e3bd9e2 Compare March 17, 2026 13:00
@stalniy stalniy marked this pull request as ready for review April 17, 2026 12:27
@stalniy stalniy requested a review from a team as a code owner April 17, 2026 12:27
Replace all usages of the deprecated loadWithPagination utility with
getAllItems from @akashnetwork/http-sdk, which includes circular loop
detection. Remove dead loadWithPagination code from deploy-web,
http-sdk, and indexer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@stalniy stalniy force-pushed the refactor/dx-replace-loadWithPagination branch from e3bd9e2 to 7c64738 Compare April 17, 2026 12:31
Copy link
Copy Markdown
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

🧹 Nitpick comments (3)
apps/deploy-web/src/queries/useLeaseQuery.ts (1)

55-55: Avoid using any type for the deployment parameter.

The deployment parameter is typed as any, which violates the coding guidelines. Consider using a more specific type like Pick<DeploymentDto, "dseq" | "groups"> | undefined to match the pattern in getDeploymentLeases.

♻️ Proposed fix
-async function getAllLeases(chainApiHttpClient: AxiosInstance, address: string, deployment?: any) {
+async function getAllLeases(chainApiHttpClient: AxiosInstance, address: string, deployment?: Pick<DeploymentDto, "dseq" | "groups">) {

As per coding guidelines: "Never use type any or cast to type any. Always define the proper TypeScript types."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/deploy-web/src/queries/useLeaseQuery.ts` at line 55, Replace the broad
any type on the deployment parameter of getAllLeases with a specific type
matching the pattern used in getDeploymentLeases (e.g., Pick<DeploymentDto,
"dseq" | "groups"> | undefined); update the function signature async function
getAllLeases(chainApiHttpClient: AxiosInstance, address: string, deployment?:
Pick<DeploymentDto, "dseq" | "groups"> | undefined) and any internal usages
expecting deployment to rely on those fields so the compiler can typecheck
correctly and avoid any casts to any.
apps/deploy-web/src/queries/useLeaseQuery.spec.tsx (2)

231-232: Consider using more specific assertion here as well.

Same suggestion as above - using expect.objectContaining() would verify the pagination params are correctly passed.

♻️ Proposed improvement
-      expect(chainApiHttpClient.get).toHaveBeenCalledWith(expect.stringContaining("filters.owner=test-address"), expect.anything());
+      expect(chainApiHttpClient.get).toHaveBeenCalledWith(
+        expect.stringContaining("filters.owner=test-address"),
+        expect.objectContaining({ params: expect.objectContaining({ "pagination.limit": 1000, "pagination.count_total": "true" }) })
+      );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/deploy-web/src/queries/useLeaseQuery.spec.tsx` around lines 231 - 232,
The second assertion is too loose about the second argument passed to
chainApiHttpClient.get; update the test so the call is asserted with
expect.objectContaining to verify pagination params are included (e.g., page,
limit, or other params) rather than using expect.anything(); locate the test
that calls chainApiHttpClient.get and change the second argument expectation to
expect.objectContaining({...}) while keeping the existing URL assertion and the
result.current.data equality check using leaseToDto(mockLeases[0], undefined as
any).

156-157: Consider using more specific assertion for the options parameter.

While expect.anything() works, the test in useGrantsQuery.spec.tsx uses expect.objectContaining() to verify the pagination params are correctly passed. This provides better test coverage for the refactored API.

♻️ Proposed improvement for more precise assertion
-      expect(chainApiHttpClient.get).toHaveBeenCalledWith(expect.stringContaining(`filters.dseq=${mockDeployment.dseq}`), expect.anything());
+      expect(chainApiHttpClient.get).toHaveBeenCalledWith(
+        expect.stringContaining(`filters.dseq=${mockDeployment.dseq}`),
+        expect.objectContaining({ params: expect.objectContaining({ "pagination.limit": 1000, "pagination.count_total": "true" }) })
+      );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/deploy-web/src/queries/useLeaseQuery.spec.tsx` around lines 156 - 157,
The test currently uses expect.anything() for the options argument to
chainApiHttpClient.get; update the assertion to use expect.objectContaining to
verify the expected query/pagination options are passed (e.g., replace
expect.anything() with expect.objectContaining({...}) so the call to
chainApiHttpClient.get includes the pagination/params you expect). Locate the
assertion in useLeaseQuery.spec.tsx referencing chainApiHttpClient.get and
ensure the object contains the relevant keys (pagination/limit/offset or params)
while keeping the URL check
(expect.stringContaining(`filters.dseq=${mockDeployment.dseq}`)) and the
result.current.data / leaseToDto expectation unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/http-sdk/src/deployment/deployment-http.service.ts`:
- Around line 170-174: The pagination callback passed to getAllItems (which
fetches DeploymentInfo using extractData and this.httpClient.get against baseUrl
with params including defaultLimit) lacks a request timeout; update the options
object passed to this.httpClient.get inside that callback to include timeout:
30000 (matching other calls in the file) so each paginated HTTP request will
time out after 30s and prevent hangs during full-list retrievals.

---

Nitpick comments:
In `@apps/deploy-web/src/queries/useLeaseQuery.spec.tsx`:
- Around line 231-232: The second assertion is too loose about the second
argument passed to chainApiHttpClient.get; update the test so the call is
asserted with expect.objectContaining to verify pagination params are included
(e.g., page, limit, or other params) rather than using expect.anything(); locate
the test that calls chainApiHttpClient.get and change the second argument
expectation to expect.objectContaining({...}) while keeping the existing URL
assertion and the result.current.data equality check using
leaseToDto(mockLeases[0], undefined as any).
- Around line 156-157: The test currently uses expect.anything() for the options
argument to chainApiHttpClient.get; update the assertion to use
expect.objectContaining to verify the expected query/pagination options are
passed (e.g., replace expect.anything() with expect.objectContaining({...}) so
the call to chainApiHttpClient.get includes the pagination/params you expect).
Locate the assertion in useLeaseQuery.spec.tsx referencing
chainApiHttpClient.get and ensure the object contains the relevant keys
(pagination/limit/offset or params) while keeping the URL check
(expect.stringContaining(`filters.dseq=${mockDeployment.dseq}`)) and the
result.current.data / leaseToDto expectation unchanged.

In `@apps/deploy-web/src/queries/useLeaseQuery.ts`:
- Line 55: Replace the broad any type on the deployment parameter of
getAllLeases with a specific type matching the pattern used in
getDeploymentLeases (e.g., Pick<DeploymentDto, "dseq" | "groups"> | undefined);
update the function signature async function getAllLeases(chainApiHttpClient:
AxiosInstance, address: string, deployment?: Pick<DeploymentDto, "dseq" |
"groups"> | undefined) and any internal usages expecting deployment to rely on
those fields so the compiler can typecheck correctly and avoid any casts to any.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f19c9e45-2a97-405a-8c63-403a8f5c3618

📥 Commits

Reviewing files that changed from the base of the PR and between 0fb1e50 and e3bd9e2.

⛔ Files ignored due to path filters (1)
  • packages/net/src/generated/netConfigData.ts is excluded by !**/generated/**
📒 Files selected for processing (10)
  • apps/deploy-web/src/queries/useDeploymentQuery.ts
  • apps/deploy-web/src/queries/useGrantsQuery.spec.tsx
  • apps/deploy-web/src/queries/useGrantsQuery.ts
  • apps/deploy-web/src/queries/useLeaseQuery.spec.tsx
  • apps/deploy-web/src/queries/useLeaseQuery.ts
  • apps/deploy-web/src/services/wallet-balances/wallet-balances.service.ts
  • apps/deploy-web/src/utils/apiUtils.ts
  • apps/indexer/src/shared/utils/query.ts
  • packages/http-sdk/src/deployment/deployment-http.service.ts
  • packages/http-sdk/src/utils/pagination.utils.ts
💤 Files with no reviewable changes (3)
  • apps/indexer/src/shared/utils/query.ts
  • apps/deploy-web/src/utils/apiUtils.ts
  • packages/http-sdk/src/utils/pagination.utils.ts

Comment on lines +170 to +174
const allDeployments = await getAllItems<DeploymentInfo>(async params => {
const response = extractData(
await this.httpClient.get<DeploymentListResponse>(baseUrl, {
params: { "pagination.limit": defaultLimit, ...params }
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Verify whether HttpClient/axios instance sets a global timeout
fd -i "httpClient.ts" packages --type f
fd -i "http.service.ts" packages --type f
rg -n --type=ts -C3 'timeout\s*:' packages/http-sdk/src

# Compare timeout usage in this service's pagination branches
rg -n --type=ts -C4 'getAllItems|deployments/list|timeout' packages/http-sdk/src/deployment/deployment-http.service.ts

Repository: akash-network/console

Length of output: 5871


🏁 Script executed:

cat -n packages/http-sdk/src/utils/httpClient.ts | head -100

Repository: akash-network/console

Length of output: 1279


🏁 Script executed:

rg -n "timeout|getAllItems" packages/http-sdk/src/utils/pagination.utils.ts -A 10 -B 2

Repository: akash-network/console

Length of output: 533


🏁 Script executed:

cat -n packages/http-sdk/src/utils/pagination.utils.ts

Repository: akash-network/console

Length of output: 1275


🏁 Script executed:

rg -n "constructor|httpClient\s*=" packages/http-sdk/src/deployment/deployment-http.service.ts -A 3 -B 3 | head -30

Repository: akash-network/console

Length of output: 322


Add timeout to the pagination fetch loop to prevent hangs.

The callback in getAllItems (lines 170-174) performs repeated HTTP calls without an explicit timeout. Since HttpClient has no global default timeout, this path can hang indefinitely if the API becomes unresponsive, stalling full-list retrievals. Other calls in the same file (lines 149, 206) use timeout: 30000—this branch should match that pattern.

Suggested patch
       const allDeployments = await getAllItems<DeploymentInfo>(async params => {
         const response = extractData(
           await this.httpClient.get<DeploymentListResponse>(baseUrl, {
-            params: { "pagination.limit": defaultLimit, ...params }
+            params: { "pagination.limit": defaultLimit, ...params },
+            timeout: 30000
           })
         );
         return { items: response.deployments, pagination: response.pagination };
       });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const allDeployments = await getAllItems<DeploymentInfo>(async params => {
const response = extractData(
await this.httpClient.get<DeploymentListResponse>(baseUrl, {
params: { "pagination.limit": defaultLimit, ...params }
})
const allDeployments = await getAllItems<DeploymentInfo>(async params => {
const response = extractData(
await this.httpClient.get<DeploymentListResponse>(baseUrl, {
params: { "pagination.limit": defaultLimit, ...params },
timeout: 30000
})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/http-sdk/src/deployment/deployment-http.service.ts` around lines 170
- 174, The pagination callback passed to getAllItems (which fetches
DeploymentInfo using extractData and this.httpClient.get against baseUrl with
params including defaultLimit) lacks a request timeout; update the options
object passed to this.httpClient.get inside that callback to include timeout:
30000 (matching other calls in the file) so each paginated HTTP request will
time out after 30s and prevent hangs during full-list retrievals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants