Need performance tuning for View::search_views()
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Mahara |
Fix Released
|
Medium
|
Aaron Wells |
Bug Description
This is a core function in lib/view.php, and it generates a monster SQL statement that finds all the views that can be seen by an individual user. The exact details of the query depend on the parameters sent to the function, but in any form it causes big performance problems once you hit the size of myportfolio.
SELECT count(*)
FROM "view" v
LEFT OUTER JOIN "collection_view" cv ON cv.view = v.id
LEFT OUTER JOIN "collection" c ON cv.collection = c.id
LEFT OUTER JOIN (
) l ON v.id = l.onview
WHERE (v.owner IS NULL OR v.owner > 0)
Changed in mahara: | |
status: | Confirmed → In Progress |
Changed in mahara: | |
milestone: | none → 15.10.0 |
Changed in mahara: | |
milestone: | 15.10.0 → 16.04.0 |
One improvement would be particularly easy. Each time you call the function, it actually executes two queries. The first is a count(*) to get the total number of results that match your search criteria, and the second is to get some portion of those results (using ORDER BY and LIMIT). Some places which call this function don't need the count(*) results, so we could change the function so that returning the count(*) is optional, and that would reduce some executions of the query.
But, it would still be good if we could get the performance of the query improved. Part of the problem, though, is that there are just a whole bunch of views in a big Mahara site. Perhaps adding some additional indices would help...