create_extra_permissions tries to create a permission eight times for every model every time
./manage.py migrate is used.
In a project with a big number of models this process can take more than a minute.
This update minimizes the number of SQL queries by:
* selecting all needed content types at once;
* selecting information about existing relevant permissions to a set that is used to check for existence of a permission before trying to create it;
* creating permissions using
./manage.py migrate runs 9 times faster with this change in my case when no new migrations are applied.