Update user audit query to be more efficient
Update user audit query to be more efficient

Trying to view user profiles other than your own with a large database
was triggering a 500 response. The root cause was the fact that the ORM
was generating a 2.2MB SQL statement, causing Postgres to choke with a
stack error.

The audit query code in lib/user.py builds up the final QuerySet by
gluing together several small parts. I discovered that the same instance
was being fed into the filter multiple times, causing the ORM to
generate a lot of duplicate clauses, bloating the query. Adding a
``distinct`` took care of that.

The fast majority of users will only edit a single instance, and our
audit table is optimized for filtering by instance ID, so I added an
additional query to fetch the ids of a users edited instances and use
that to limit the scope of the query, rather than limiting it to the
larger list of visible instances.

RickMohr/otm-core,clever-crow-consulting/otm-core,RickMohr/otm-core,RickMohr/otm-core,RickMohr/otm-core,recklessromeo/otm-core,maurizi/otm-core,maurizi/otm-core,maurizi/otm-core,clever-crow-consulting/otm-core,maurizi/otm-core,recklessromeo/otm-core,clever-crow-consulting/otm-core,recklessromeo/otm-core,clever-crow-consulting/otm-core,recklessromeo/otm-core