Tickets::getAllTickets() is very inefficient
Currently there are a couple of thousand issues on DtW, which makes loading the ticket moderation page very slow. Sometimes it results in a 500.
Looking at the code, I see two obvious problems:
- In getAllTickets' query, there is a subquery per ticket id.
- After the query, for each ticket a "wrapper" object is made. This again results in multiple queries per ticket id.
The first might be solved by joining on something like "select ticket_id, max(sent)" instead of ticket_messages itself. (Not sure if the order-by on user_id is really needed; it might complicate things.)
The second is a bit trickier, but might be solved by loading data on demand and perhaps constructing the entry with the information you already have from getAllTickets' query.
Another thing that might be easier and resolve the issue in most cases is to implement a filter on the page, that defaults to showing only open tickets.