Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk processing #72

Open
mvrhov opened this issue Nov 21, 2016 · 5 comments
Open

Bulk processing #72

mvrhov opened this issue Nov 21, 2016 · 5 comments
Milestone

Comments

@mvrhov
Copy link

mvrhov commented Nov 21, 2016

What's the best way to process something in bulk when using iterator e.g.

$foos = $model->findAll();

foreach ($foos as $foo) {
	if (foo) {
		$existed++;
	} else {
		$model->deleteOne($foo);
		$removed++;
	}

	unset($foo);
}

unset doesn't seem to do anything. And the memory just keeps going up.

@chanmix51
Copy link
Member

That’s because of the IdentityMapper. It keeps a cache of all the instances fetched from the database to ensure that if a record is fetched twice it will return the same instance hence an update on the instance will update it everywhere.

The model manager is an entity CRUD oriented model. What you are trying to do in PHP would by far be better done in SQL using the SimpleQueryManager:

WITH
   deleted_foo AS (DELETE FROM foo WHERE {condition} RETURNING foo_id)
SELECT 
  count(foo.foo_id)         AS existing_count,
  count(deleted_foo.foo_id) AS deleted_count
FROM foo, deleted_foo

@mvrhov
Copy link
Author

mvrhov commented Nov 22, 2016

Well that was not an good example :)
What to remove was to be decided after the record was fetched and looking at the disk if the file exists.

@chanmix51
Copy link
Member

I think maybe you should use a ConvertedResultIterator for this, you do not really need OO entities for this.

@mvrhov
Copy link
Author

mvrhov commented Dec 6, 2016

This means that I have to mix arrays and entities which is not nice. Having the ability to clear those entities would be nice.
Also using pomm in running long running processes e.g queue processors would benefit from this.

@chanmix51
Copy link
Member

This is the job of another model manager, it will pop in in 3.0

@chanmix51 chanmix51 added this to the 3.0 milestone Feb 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants