Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Issue: Fix bug when ordering by duedate with labels
Browse files Browse the repository at this point in the history
When using el.in(labels.id, labelIds) with odering by duedate, it generates a sql that is using join. like:

select distinct t0.id c0, t0.title c1, t0.created_date c2, t0.updated_date c3, t0.author_id c4, t0.author_login_id c5,
t0.author_name c6, t0.project_id c7, t0.number c8, t0.num_of_comments c9, t0.state c10, t0.due_date c11, t0.milestone_id c12,
t0.assignee_id c13
from issue t0 join issue_issue_label u1z_ on u1z_.issue_id = t0.id  join issue_label u1 on u1.id = u1z_.issue_label_id
where t0.project_id = 42  and t0.state = 1  and u1.id in (33)
order by case when due_date is null then cast('0001-01-01 00:00:00' as timestamp) else due_date end desc
limit 16;

This query must contains `case when due_date is null then cast('0001-01-01 00:00:00' as timestamp) else due_date end`
in the select phrase, because when a @fomula(sql) is used in order by phrase with join, the sql should be in the select phrase too,
but ebean doesn't generate query like that.

So, I have changed it to not to use join query. like:

select t0.id c0, t0.title c1, t0.created_date c2, t0.updated_date c3, t0.author_id c4, t0.author_login_id c5,
t0.author_name c6, t0.project_id c7, t0.number c8, t0.num_of_comments c9, t0.state c10, t0.due_date c11, t0.milestone_id c12,
t0.assignee_id c13
from issue t0 where t0.project_id = 42  and t0.state = 1  and t0.id in (123, 34, 234, 5345, 346, 34134)
order by case when due_date is null then cast('0001-01-01 00:00:00' as timestamp) else due_date end desc
limit 16;

It will be more slower then now but it works.
  • Loading branch information
Keesun Baik committed Apr 22, 2015
1 parent 82de4cd commit c44efc8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/support/SearchCondition.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ public ExpressionList<Issue> asExpressionList(Project project) {
}

if (CollectionUtils.isNotEmpty(labelIds)) {
el.in("labels.id", labelIds);
Set<IssueLabel> labels = IssueLabel.finder.where().idIn(new ArrayList<>(labelIds)).findSet();
el.in("id", Issue.finder.where().in("labels", labels).findIds());
}

if (StringUtils.isNotBlank(orderBy)) {
Expand Down

0 comments on commit c44efc8

Please sign in to comment.