Project

General

Profile

Actions

Defect #33290

closed

Unnecessary database access when IssueQuery class is defined

Added by Kevin Fischer over 4 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Plugin API
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

During plugin development I found out that the definition of the Query class accesses the database just by being defined.

The reason for this is the `groupable` method in the `TimestampQueryColumn` class which tries to access the current user.

https://github.com/redmine/redmine/blob/4.1.1/app/models/query.rb#L89-L93

This method is called during the constructor (which is called in the query column definitions in the class body of IssueQuery)

https://github.com/redmine/redmine/blob/4.1.1/app/models/issue_query.rb#L36-L51

Why is this a problem?

In case your database is not yet created and/or migrated, any source code which just references the IssueQuery class will raise an exception since it cannot find the database/table.

And in general I think it's not good to access the database just by defining a class.

Patch

I attached a patch which also acts as a code cleanup/refactoring. It moves the group by statement into its own method. Before the boolean property `groupable` was just redefined to contain the group by statement as well, which was confusing in the first place in my opinion.

I ran all tests locally and they passed.


Files


Related issues

Related to Redmine - Feature #2679: Ticket groupingClosed2009-02-05

Actions
Related to Redmine - Feature #13803: Implement grouping issues by date (start, due, creation, update, closing dates)ClosedJean-Philippe Lang

Actions
Related to Redmine - Defect #35115: Time entries are broken if grouped by project and issue custom fieldsClosedGo MAEDA

Actions
Has duplicate Redmine - Defect #33121: IssueQuery not usable from pluginsClosed

Actions
Actions

Also available in: Atom PDF