Patch #33431

Better performance for Time entries without issue and activity filters

Added by Alexander Meindl 6 months ago. Updated 6 months ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Performance
Target version:Candidate for next major release

Description

At the moment all time entry queries join issue and activities. If there is a large number of time entries and issues, this is a big performance issue.

Some of our customers have more than 500.000 time entries and even more issues. A query without a time filter requires minutes. With this attached patch this improves it to some seconds.

Issue and activity joins are only add, if they are required.

It would be great, to get this in Redmine.

time_query_performace.patch Magnifier (1.64 KB) Alexander Meindl, 2020-05-11 13:47

time_query_performace_v2.patch Magnifier (790 Bytes) Alexander Meindl, 2020-05-12 14:49

time_query_performace_v3.patch Magnifier (591 Bytes) Alexander Meindl, 2020-05-12 16:21

History

#1 Updated by Go MAEDA 6 months ago

  • Category changed from Time tracking to Performance
  • Target version set to Candidate for next major release

#2 Updated by Go MAEDA 6 months ago

Looks good to me.

#3 Updated by Alexander Meindl 6 months ago

My patch has problems with column sort order.

But I found the real problem now. It is a missing condition to project_id for Enumeration. I am working on a new patch to fix this problem. Please do not commit the current patch.

#4 Updated by Marius BALTEANU 6 months ago

Alexander Meindl wrote:

My patch has problems with column sort order.

But I found the real problem now. It is a missing condition to project_id for Enumeration. I am working on a new patch to fix this problem. Please do not commit the current patch.

Nice feature, but we should have tests for this change.

#5 Updated by Alexander Meindl 6 months ago

Here is my new fixed version.

Adding

where("#{Enumeration.table_name}.project_id = #{TimeEntry.table_name}.project_id")

fixed the problem. But I moved activity join from base_scope to results_scope, because as I understood it, activity join is not required for totals and count.

I am not sure, how I can test this change with an additional test. Existing test should work, of course.

#6 Updated by Alexander Meindl 6 months ago

And again, now all tests are running.

With my test data, /time_entries without filters

  • without patch: ActiveRecord: 345038.1ms
  • with patch ActiveRecord: 6038.4ms

This is not perfect, but way better than before. At the moment I have no idea how it can be more improved. The problem is table layout of enumerations table.

Also available in: Atom PDF