Skip to content

fix: [#1018] fetch rows in chunks of 1000 in db.Each - #1582

Open
JGamboa wants to merge 2 commits into
goravel:masterfrom
JGamboa:fix/db-each-chunk-size
Open

JGamboa wants to merge 2 commits into
goravel:masterfrom
JGamboa:fix/db-each-chunk-size

Conversation

@JGamboa

@JGamboa JGamboa commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

📑 Description

Closes goravel/goravel#1018

db.Query.Each used Chunk(1): one LIMIT 1 OFFSET n query per row plus a final empty one. Now it fetches rows in chunks of 1000, the same default as Laravel's each(), and keeps the public API and the per-row callback. With fewer than 1000 rows it runs a single query, and a callback error still stops the iteration right away.

✅ Checks

  • Added test cases for my code
    • TestDBTestSuite/TestEach in tests/db_test.go checks the order, that a single query appears in the query log, and that the iteration stops on a callback error. It fails on master (4 queries for 3 rows) and passes here on all four drivers. There were no Each tests before.

db.Query.Each called Chunk(1, ...), issuing one LIMIT 1 OFFSET n query per
row plus a final empty one (N+1 queries for N rows, each OFFSET scan
getting slower). Fetch rows in chunks of 1000 instead, as Laravel does,
while still invoking the callback once per row.
@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.06%. Comparing base (7ffe4a8) to head (562a168).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1582      +/-   ##
==========================================
+ Coverage   72.91%   73.06%   +0.15%     
==========================================
  Files         412      412              
  Lines       26893    26893              
==========================================
+ Hits        19608    19649      +41     
+ Misses       7283     7242      -41     
  Partials        2        2              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JGamboa
JGamboa marked this pull request as ready for review October 18, 2026 23:47
@JGamboa
JGamboa requested a review from a team as a code owner October 18, 2026 23:47
@JGamboa

JGamboa commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

Review Ready

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.

DB Each runs one query per row (Chunk(1) with OFFSET)

1 participant