Feature #44364
openImprove the performance of the issues API when listing issues
Description
When listing issues, the issues API renders the tracker, assignee, category, target version and custom field values of every issue. Most of these associations are loaded one issue at a time, so the number of queries grows with the page size. Preloading them reduces the number of queries by about 90% for a full page. In my test, it also cut the response time by more than half.
The first patch adds a :preload option to IssueQuery#issues, so that callers can specify the associations they need. The issues API uses this option when listing issues. Attachments are only preloaded when include=attachments is given in the API request.
he second patch is independent of the first. index.api.rsb and show.api.rsb render only the id of the parent issue, but they test its presence through the
association, which loads the parent issue.
Measured on GET /issues.json?limit=100 with 100 issues in the response, including 34 with a parent issue (SQLite, development machine):
| without custom fields | 5 custom fields | |
|---|---|---|
| trunk | 398 queries (76 ms) | 598 queries (140 ms) |
| patch 1 | 86 queries (30 ms) | 87 queries (41 ms) |
| patch 1 + 2 | 52 queries (26 ms) | 53 queries (36 ms) |
On trunk, adding five custom fields increases the number of queries from 398 to 598. With the patches, it only increases from 52 to 53.
Files