Project

General

Profile

Actions

Patch #42144

open

Optimize IssuesController#show by skipping time tracking queries when disabled

Added by Go MAEDA about 16 hours ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Performance
Start date:
Due date:
% Done:

0%

Estimated time:

Description

Currently, when the time_tracking module is disabled, the IssuesController#show action still attempts to load TimeEntryActivity records and related data, as shown below.

The attached patch improves the IssuesController#show action by ensuring that queries related to TimeEntryActivity and time tracking data are only executed when the time_tracking module is enabled for the project. By adding a condition to check the module's status, the patch eliminates unnecessary database queries.

  TimeEntryActivity Pluck (0.0ms)  SELECT "enumerations"."parent_id" FROM "enumerations" WHERE "enumerations"."type" = ? AND "enumerations"."project_id" = ? ORDER BY "enumerations"."position" ASC  [["type", "TimeEntryActivity"], ["project_id", 5]]
  ↳ app/models/project.rb:269:in `activities'
  Member Load (0.1ms)  SELECT "members".* FROM "members" INNER JOIN "projects" ON "projects"."id" = "members"."project_id" WHERE "members"."user_id" = ? AND "projects"."status" != ? AND "members"."project_id" = ? ORDER BY "members"."id" ASC LIMIT ?  [["user_id", 1], ["status", 9], ["project_id", 5], ["LIMIT", 1]]
  ↳ app/models/user.rb:601:in `block in membership'
  Role Load (0.1ms)  SELECT DISTINCT "roles".* FROM "roles" INNER JOIN "member_roles" ON "roles"."id" = "member_roles"."role_id" WHERE "member_roles"."member_id" = ? AND "roles"."default_time_entry_activity_id" IS NOT NULL  [["member_id", 8]]
  ↳ app/models/time_entry_activity.rb:68:in `sort'
  TimeEntryActivity Load (0.1ms)  SELECT "enumerations".* FROM "enumerations" WHERE "enumerations"."type" = ? AND "enumerations"."is_default" = ? ORDER BY "enumerations"."position" ASC LIMIT ?  [["type", "TimeEntryActivity"], ["is_default", 1], ["LIMIT", 1]]
  ↳ app/models/enumeration.rb:53:in `default'
  CACHE TimeEntryActivity Pluck (0.0ms)  SELECT "enumerations"."parent_id" FROM "enumerations" WHERE "enumerations"."type" = ? AND "enumerations"."project_id" = ? ORDER BY "enumerations"."position" ASC  [["type", "TimeEntryActivity"], ["project_id", 5]]
  ↳ app/models/project.rb:269:in `activities'
  TimeEntryActivity Load (0.1ms)  SELECT "enumerations".* FROM "enumerations" WHERE "enumerations"."type" = ? AND (enumerations.project_id IS NULL OR enumerations.project_id = ?) AND "enumerations"."active" = ? ORDER BY "enumerations"."position" ASC  [["type", "TimeEntryActivity"], [nil, 5], ["active", 1]]
  ↳ app/models/time_entry_activity.rb:28:in `default'
  CACHE TimeEntryActivity Pluck (0.0ms)  SELECT "enumerations"."parent_id" FROM "enumerations" WHERE "enumerations"."type" = ? AND "enumerations"."project_id" = ? ORDER BY "enumerations"."position" ASC  [["type", "TimeEntryActivity"], ["project_id", 5]]
  ↳ app/models/project.rb:269:in `activities'
  TimeEntryActivity Exists? (0.1ms)  SELECT 1 AS one FROM "enumerations" WHERE "enumerations"."type" = ? AND (enumerations.project_id IS NULL OR enumerations.project_id = ?) AND "enumerations"."active" = ? AND "enumerations"."id" = ? LIMIT ?  [["type", "TimeEntryActivity"], [nil, 5], ["active", 1], ["id", 10], ["LIMIT", 1]]
  ↳ app/models/time_entry_activity.rb:28:in `default'
  CACHE TimeEntryActivity Load (0.0ms)  SELECT "enumerations".* FROM "enumerations" WHERE "enumerations"."type" = ? AND "enumerations"."is_default" = ? ORDER BY "enumerations"."position" ASC LIMIT ?  [["type", "TimeEntryActivity"], ["is_default", 1], ["LIMIT", 1]]
  ↳ app/models/enumeration.rb:53:in `default'
  TimeEntryActivity Count (0.1ms)  SELECT COUNT(*) FROM "enumerations" WHERE "enumerations"."type" = ? AND (enumerations.project_id IS NULL OR enumerations.project_id = ?) AND "enumerations"."active" = ?  [["type", "TimeEntryActivity"], [nil, 5], ["active", 1]]
  ↳ app/models/time_entry_activity.rb:82:in `default_activity_id'
  CACHE TimeEntryActivity Load (0.0ms)  SELECT "enumerations".* FROM "enumerations" WHERE "enumerations"."type" = ? AND (enumerations.project_id IS NULL OR enumerations.project_id = ?) AND "enumerations"."active" = ? ORDER BY "enumerations"."position" ASC  [["type", "TimeEntryActivity"], [nil, 5], ["active", 1]]
  ↳ app/models/time_entry_activity.rb:87:in `detect'

Files

No data to display

Actions

Also available in: Atom PDF