Opened 10 years ago
Last modified 3 years ago
#11826 new enhancement
Optimize ticket.query.execute
Reported by: | anonymous | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | next-major-releases |
Component: | query system | Version: | 1.1.2 |
Severity: | minor | Keywords: | performance |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description (last modified by )
The ticket.query.execute function could be optimised somewhat…
if self.max == 0: self.has_more_pages = False self.offset = 0 else: self.has_more_pages = True self.offset = self.max * (self.page - 1)
source:trunk/trac/ticket/query.py?rev=13234#L110
self.num_items = self._count(sql, args) if self.num_items <= self.max: self.has_more_pages = False if self.has_more_pages:
source:trunk/trac/ticket/query.py?rev=13234#L295
if self.max = 0 this: self.num_items = self._count(sql, args)
is useless since if self.has_more_pages:
will always be False.
So I suggest adding something like:
if self.has_more_pages: // This line self.num_items = self._count(sql, args) if self.num_items <= self.max: self.has_more_pages = False if self.has_more_pages:
That would save one sql-query which in worst case scenario could double(?) the execution time I suppose
Attachments (0)
Change History (10)
comment:1 by , 10 years ago
Description: | modified (diff) |
---|
comment:2 by , 10 years ago
Milestone: | → 1.1.3 |
---|---|
Priority: | normal → low |
Severity: | normal → minor |
Version: | → 1.1.2 |
comment:3 by , 10 years ago
Then it might have been my bad, since it just returns the result i didn't think of that it could be used later…
However it might be better/more optimized to calculate num_items
/has_more_pages
on demand.
I noticed this when I used the xmlrpcplugin with max=0, so the count query was a bit .. unexpected…
comment:4 by , 10 years ago
I've had the same issue while developing th:ExcelDownloadPlugin. The plugin provides download in excel format from query page and converts always all tickets from query (max parameter is ignored) to excel format.
Currently, the plugin overrides _count
instance method of Query
instance to prevent SELECT COUNT(*)
query. See source:exceldownloadplugin/0.12/tracexceldownload/ticket.py@13866:180-188#L163.
comment:5 by , 10 years ago
I do understand that Query
can't work perfect for everyone, but its never nice when you have to hack around it like that =/
I propose adding a separate method has_more_pages
instead, so it can be calculated on demand instead
comment:6 by , 10 years ago
Milestone: | 1.1.3 → next-dev-1.1.x |
---|
Retargeting tickets in milestone:1.1.3 that have no owner. Please retarget as appropriate.
comment:7 by , 9 years ago
Keywords: | performance added |
---|---|
Priority: | low → normal |
Added keyword 'performance'. Upped priority to normal.
comment:8 by , 9 years ago
Milestone: | next-dev-1.1.x → next-dev-1.3.x |
---|
Narrowing focus for milestone:1.2. Please move ticket to milestone:1.2 if you intend to fix it.
comment:10 by , 5 years ago
Milestone: | next-dev-1.5.x → next-major-releases |
---|
Well, we compute
.num_items
not just to set the.has_more_pages
flag, but also because we need that information. The question is if in this particular case (which I admit we don't use or test much, because it's probably a bad idea to not paginate the results), we could retrieve the.num_items
from the main query. It looks like we could easily do that.