{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/9681","labels_url":"https://api.github.com/repos/laravel/framework/issues/9681/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/9681/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/9681/events","html_url":"https://github.com/laravel/framework/pull/9681","id":95853520,"number":9681,"title":"[5.1] Fix for chunk()","user":{"login":"arrilot","id":2826480,"avatar_url":"https://avatars.githubusercontent.com/u/2826480?v=3","gravatar_id":"","url":"https://api.github.com/users/arrilot","html_url":"https://github.com/arrilot","followers_url":"https://api.github.com/users/arrilot/followers","following_url":"https://api.github.com/users/arrilot/following{/other_user}","gists_url":"https://api.github.com/users/arrilot/gists{/gist_id}","starred_url":"https://api.github.com/users/arrilot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arrilot/subscriptions","organizations_url":"https://api.github.com/users/arrilot/orgs","repos_url":"https://api.github.com/users/arrilot/repos","events_url":"https://api.github.com/users/arrilot/events{/privacy}","received_events_url":"https://api.github.com/users/arrilot/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-07-18T19:34:35Z","updated_at":"2015-07-31T10:15:43Z","closed_at":"2015-07-19T03:01:53Z","pull_request":{"url":"https://api.github.com/repos/laravel/framework/pulls/9681","html_url":"https://github.com/laravel/framework/pull/9681","diff_url":"https://github.com/laravel/framework/pull/9681.diff","patch_url":"https://github.com/laravel/framework/pull/9681.patch"},"body":"Closes #9649\r\n\r\nThis one is relatively hard to review. Sorry about that.\r\n\r\nAs you can see in the issue limits and offsets are completely ignored if `chunk()` is used instead of `get()`.\r\nThis happens because chunk overrides those properties internally.\r\n\r\nAlthough it's a rare usecase, in my opinion it's a bug and should be fixed in 5.1 therefore."},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/126634769","html_url":"https://github.com/laravel/framework/pull/9681#issuecomment-126634769","issue_url":"https://api.github.com/repos/laravel/framework/issues/9681","id":126634769,"user":{"login":"Shkeats","id":2048674,"avatar_url":"https://avatars.githubusercontent.com/u/2048674?v=3","gravatar_id":"","url":"https://api.github.com/users/Shkeats","html_url":"https://github.com/Shkeats","followers_url":"https://api.github.com/users/Shkeats/followers","following_url":"https://api.github.com/users/Shkeats/following{/other_user}","gists_url":"https://api.github.com/users/Shkeats/gists{/gist_id}","starred_url":"https://api.github.com/users/Shkeats/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shkeats/subscriptions","organizations_url":"https://api.github.com/users/Shkeats/orgs","repos_url":"https://api.github.com/users/Shkeats/repos","events_url":"https://api.github.com/users/Shkeats/events{/privacy}","received_events_url":"https://api.github.com/users/Shkeats/received_events","type":"User","site_admin":false},"created_at":"2015-07-31T10:15:43Z","updated_at":"2015-07-31T10:15:43Z","body":"@taylorotwell I also can't see any reason why chunk shouldn't internally respect a limit and offset that has already been set. It's not clear that chunk is *meant* to override limits and offsets. It seems to me that rather it *happens* to override limits and offsets because of how it's implemented. I think it's a valid usecase to want to chunk through a limited or offset number of records. \r\n\r\nSay I want to do some processing on 40,000 records with 4 worker threads for jobs and I want them to do 10,000 records each in batches of 500, currently you need to calculate the limits and offsets yourself, set up a loop and call the queries incrementing the skip() and take() as you go.\r\n\r\nChunk could handle this easily if I could run the following on each worker.\r\n\r\n-1 Model::take(10000)->chunk(500,..)\r\n-2 Model::skip(10000)->take(10000)->chunk(500,..)\r\n-3 Model::skip(20000)->take(10000)->chunk(500,..)\r\n-4 Model::skip(30000)->take(10000)->chunk(500,..)\r\n\r\nI think the above lines are conceptually sound and very readable. \r\n\"With this model, skip the first 10,000 rows, take the next 10,000 in batches of 500 passing them to this closure.\""}}