{"action":"created","issue":{"url":"https://api.github.com/repos/django-guardian/django-guardian/issues/451","repository_url":"https://api.github.com/repos/django-guardian/django-guardian","labels_url":"https://api.github.com/repos/django-guardian/django-guardian/issues/451/labels{/name}","comments_url":"https://api.github.com/repos/django-guardian/django-guardian/issues/451/comments","events_url":"https://api.github.com/repos/django-guardian/django-guardian/issues/451/events","html_url":"https://github.com/django-guardian/django-guardian/pull/451","id":171441918,"number":451,"title":"Improve performance of get_objects_for_user","user":{"login":"PierreF","id":359833,"avatar_url":"https://avatars.githubusercontent.com/u/359833?v=3","gravatar_id":"","url":"https://api.github.com/users/PierreF","html_url":"https://github.com/PierreF","followers_url":"https://api.github.com/users/PierreF/followers","following_url":"https://api.github.com/users/PierreF/following{/other_user}","gists_url":"https://api.github.com/users/PierreF/gists{/gist_id}","starred_url":"https://api.github.com/users/PierreF/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PierreF/subscriptions","organizations_url":"https://api.github.com/users/PierreF/orgs","repos_url":"https://api.github.com/users/PierreF/repos","events_url":"https://api.github.com/users/PierreF/events{/privacy}","received_events_url":"https://api.github.com/users/PierreF/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-16T15:18:00Z","updated_at":"2016-09-04T02:43:16Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/django-guardian/django-guardian/pulls/451","html_url":"https://github.com/django-guardian/django-guardian/pull/451","diff_url":"https://github.com/django-guardian/django-guardian/pull/451.diff","patch_url":"https://github.com/django-guardian/django-guardian/pull/451.patch"},"body":"Make sure get_objects_for_user with default option (use_groups=True and\r\nany_perm=False) benefit from direct foreign keys and do not retrive the\r\nfull list in Python.\r\n\r\nAlso use set() instead of list(), as it's fastest to let Python does\r\ndeduplicating rather than database.\r\n\r\nI've huge performance benefits with this change. Our application is using django-rest-framwork with [DjangoObjectPermissionsFilter](http://www.django-rest-framework.org/api-guide/filtering/#djangoobjectpermissionsfilter). Our user has access to ~5000 objects though group. Due to the way our group are built, user belong to 2 groups and each group as access to the same ~5000 objects\r\n\r\nWith a PostgreSQL database (on localhost), I've the following time to show one object:\r\n\r\nTest | Average time per get\r\n-------|---------\r\nUsing generic FK | 220 ms\r\nUsing direct FK   | 260 ms ! (a bit strange :))\r\nWith this PR and generic FK |  200 ms\r\nWith this PR and direct FK | 46 ms\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/django-guardian/django-guardian/issues/comments/244581048","html_url":"https://github.com/django-guardian/django-guardian/pull/451#issuecomment-244581048","issue_url":"https://api.github.com/repos/django-guardian/django-guardian/issues/451","id":244581048,"user":{"login":"ad-m","id":3618479,"avatar_url":"https://avatars.githubusercontent.com/u/3618479?v=3","gravatar_id":"","url":"https://api.github.com/users/ad-m","html_url":"https://github.com/ad-m","followers_url":"https://api.github.com/users/ad-m/followers","following_url":"https://api.github.com/users/ad-m/following{/other_user}","gists_url":"https://api.github.com/users/ad-m/gists{/gist_id}","starred_url":"https://api.github.com/users/ad-m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ad-m/subscriptions","organizations_url":"https://api.github.com/users/ad-m/orgs","repos_url":"https://api.github.com/users/ad-m/repos","events_url":"https://api.github.com/users/ad-m/events{/privacy}","received_events_url":"https://api.github.com/users/ad-m/received_events","type":"User","site_admin":false},"created_at":"2016-09-04T02:43:16Z","updated_at":"2016-09-04T02:43:16Z","body":"Thank you @PierreF . Good job.\r\n![giphy](https://cloud.githubusercontent.com/assets/3618479/18228703/10afea46-725a-11e6-8477-0957ce46c173.gif)\r\n"}}
{"actor":{"display_login":"ad-m"}}