Optimize /admin/applications so that it does not timeout
On our dev instance, /admin/applications as not loading because:
- There was an unindexed query by
application_id
. - There was an expensive query that attempted to load 1 million unique entries via ActiveRecord just to find the unique count.
We fix the first issue by adding an index for that column.
We fix the second issue with a simple SELECT COUNT(DISTINCT resource_owner_id)
SQL query. There was also an N+1 query that was fixed as well.
In addition, we add pagination to avoid loading more than 20 applications at once.
Edited by Stan Hu