lukaszb/django-guardian — pull request #148 by ggreer (2013-06-17 10:25:03+00:00)
Title: Faster queries in get_objects_for_user when use_groups=False or any_perm=True

If use_groups=False or any_perm=True, we don't have to build a pk list to figure out what objects a user has access to. This means no more SQL like...

... AND "app_model"."id" IN (6, 7, 35, 36, 41, 43, 45, ... 4175, 4178, 4179, 4184, 4186) ...

...when fetching objects for a user. Tests pass. I also ran the old code in parallel with the new on a staging instance of my site and had it raise an exception if any results were different. They never were.

In my benchmarks, fetching objects for a user now takes 0.002 seconds. The old code took 0.01 seconds for the same call. More importantly, it was nearing PostgreSQL's default maximum query size.