Skip to content

Conversation

@shantanugupta2004
Copy link
Contributor

Fixes #15508
Addresses the issue where the "Export View" functionality was not exporting all records from a view. Users reported that only a subset of records were exported, even when the view contained more. This led to incomplete data exports.

The core of the problem was found within the useLazyFetchAllRecords hook. The fetchMoreRecordsLazy function, which is responsible for fetching subsequent pages of data during the export process, was inadvertently using a default page limit (DEFAULT_SEARCH_REQUEST_LIMIT of 60 records) instead of the intended pageSize (200 records). This discrepancy caused the export process to prematurely stop fetching records.

The PR modifies packages/twenty-front/src/modules/object-record/hooks/useLazyFetchAllRecords.ts to explicitly pass the limit parameter (which correctly reflects the pageSize) to the fetchMoreRecordsLazy function. This ensures that all subsequent data fetches during an export operation adhere to the configured page size, allowing for the complete retrieval of all records.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

This PR fixes a critical pagination bug in the export functionality where only a subset of records were being exported (560 out of 1200 in the reported case).

Root Cause:
The useLazyFetchAllRecords hook was calling fetchMoreRecordsLazy() without passing the limit parameter. This caused the function to fall back to its default parameter value of DEFAULT_SEARCH_REQUEST_LIMIT (60 records) instead of using the configured pageSize (200 records for exports).

The Fix:
Changed line 90 in useLazyFetchAllRecords.ts from:

const rawResult = await fetchMoreRecordsLazy();

to:

const rawResult = await fetchMoreRecordsLazy(limit);

This ensures that subsequent pagination requests during export use the same page size as the initial request, allowing all records to be fetched correctly.

Impact:

  • Exports now correctly retrieve all records from views
  • The fix is minimal and surgical, changing only the problematic function call
  • No changes to API contracts or function signatures
  • Existing tests should continue to pass as the function signature already supported the optional limit parameter

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it's a one-line fix that correctly addresses a clear pagination bug
  • The fix is straightforward and correct: it passes the limit parameter that was already available in scope to a function that was designed to accept it. The function signature in useLazyFetchMoreRecordsWithPagination.ts line 92 shows async (limit = DEFAULT_SEARCH_REQUEST_LIMIT), confirming this parameter was always intended to be passed. The change eliminates a mismatch between the page size calculation and actual fetching behavior, resolving the incomplete export issue without introducing new logic or side effects
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/twenty-front/src/modules/object-record/hooks/useLazyFetchAllRecords.ts 5/5 Fixed pagination bug by passing limit parameter to fetchMoreRecordsLazy, preventing premature termination of exports

Sequence Diagram

sequenceDiagram
    participant User
    participant ExportFlow as Export Flow
    participant Hook as useLazyFetchAllRecords
    participant LazyFetch as fetchMoreRecordsLazy
    participant API as GraphQL API

    User->>ExportFlow: Click "Export View"
    ExportFlow->>Hook: Call fetchAllRecords()<br/>(limit=200)
    Hook->>API: Initial query (limit=200)
    API-->>Hook: Returns 200 records + hasNextPage=true
    
    alt Before Fix
        Hook->>LazyFetch: fetchMoreRecordsLazy()<br/>(no limit param)
        Note over LazyFetch: Uses DEFAULT_SEARCH_REQUEST_LIMIT=60
        LazyFetch->>API: Fetch with limit=60
        API-->>LazyFetch: Returns 60 records
        Note over Hook: Calculates remaining pages<br/>using limit=200, but fetches<br/>only 60 per page
        Note over Hook: Stops prematurely<br/>(560 out of 1200 records)
    end
    
    alt After Fix
        Hook->>LazyFetch: fetchMoreRecordsLazy(200)<br/>(passes limit param)
        Note over LazyFetch: Uses provided limit=200
        LazyFetch->>API: Fetch with limit=200
        API-->>LazyFetch: Returns 200 records
        Note over Hook: Continues until all pages fetched
        Hook-->>ExportFlow: All 1200 records
    end
    
    ExportFlow-->>User: Complete export with all records
Loading

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

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

Thank you @shantanugupta2004 :)

@charlesBochet charlesBochet merged commit 06b8ea7 into twentyhq:main Nov 10, 2025
58 checks passed
@github-actions
Copy link
Contributor

Thanks @shantanugupta2004 for your contribution!
This marks your 2nd PR on the repo. You're top 15% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

NotYen pushed a commit to NotYen/twenty-ym that referenced this pull request Nov 10, 2025
Fixes twentyhq#15508 
Addresses the issue where the "Export View" functionality was not
exporting all records from a view. Users reported that only a subset of
records were exported, even when the view contained more. This led to
incomplete data exports.

The core of the problem was found within the `useLazyFetchAllRecords`
hook. The `fetchMoreRecordsLazy` function, which is responsible for
fetching subsequent pages of data during the export process, was
inadvertently using a default page limit (`DEFAULT_SEARCH_REQUEST_LIMIT`
of 60 records) instead of the intended `pageSize` (200 records). This
discrepancy caused the export process to prematurely stop fetching
records.

The PR modifies
`packages/twenty-front/src/modules/object-record/hooks/useLazyFetchAllRecords.ts`
to explicitly pass the `limit` parameter (which correctly reflects the
`pageSize`) to the `fetchMoreRecordsLazy` function. This ensures that
all subsequent data fetches during an export operation adhere to the
configured page size, allowing for the complete retrieval of all
records.
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.

Export view doesn't export all records

2 participants