Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

results are missed when you modify the results during the batch #1

Closed
wants to merge 7 commits into
from

Conversation

Projects
None yet
3 participants

Hi,

First off, thank you very much for this great extension to data mapper. Its exactly what I needed.

I found a bug though when during the batch you also modify the results in the batch. For example, if you have a model with a name String. If you batch query all of the instances where the name is nil and in the block you set the name to a value and save the model, then the batch query will only find about half of the results.

The active record guys have a different solution that uses ordering by the id and querying in each iteration ids greater than the last result's id. Basically, I just copied their implementation in batches.rb and modified it to work with DataMapper.

There are a few consequences of this implementation. The caller can't specify the order. The model must have a single Serial property as its primary key. Finally I couldn't implement the [], at and first methods so I deleted them (I didn't put much thought into it though, so maybe there is a way).

I'm sorry I didn't write any tests for this. If I get around to it, I'll send you another pull request.

Thanks again for your work on this project. I really appreciate it.

Best Regards,
Austin

Owner

postmodern commented Sep 14, 2011

Hmm, I did not expect modification of the chunks. @dkubb can I get your opinion on how to handle this use-case?

dkubb commented Sep 15, 2011

@postmodern I'd probably need an example to see exactly what @austinmoore means.

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