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

Reduce memory usage of clean_orphan_obj_perms #463

Merged
merged 1 commit into from Oct 12, 2016

Conversation

PierreF
Copy link
Contributor

@PierreF PierreF commented Oct 12, 2016

We use generic FK for your permission and don't yet (shame on us :)) delete permission object when object is deleted.

Therefor we use from time to time clean_orphan_obj_perms... but it iterate over ALL permission objects, and we have quiet a lots of them (about 100k)... this cause clean_orphan_obj_perms to cache all objects and consume way to much memory (multiple Gb).

This is a known issue of Django with a known solution: use iterator.

This PR use iterator() for clean_orphan_obj_perms when iterating over all permission objects.

Use .iterator() on QuerySet to limit memory usage and avoid Django to
cache all objects.
@lukaszb
Copy link
Contributor

lukaszb commented Oct 12, 2016

Thanks, that definitely makes sense!

@lukaszb lukaszb merged commit 0d85c01 into django-guardian:devel Oct 12, 2016
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.

None yet

2 participants