Commit 7b7b249e authored by Jan Provaznik's avatar Jan Provaznik

Replace .having with .where in calendar query

the current syntax doesn't work properly in Rails 5, the resulting query
looks like:
HAVING "events"."project_id" IN (0)

instead of:
HAVING "events"."project_id" IN (SELECT "projects"."id" FROM...

Also we should not use ActiveRecord internal methods. In this case we
can filter projects in WHERE clause instead of doing this in HAVING
clause. Usage of WHERE should be also more efficient because grouping
is then done on much smaller subset of records.
parent 5b1416aa
...@@ -85,7 +85,7 @@ module Gitlab ...@@ -85,7 +85,7 @@ module Gitlab
.select(t[:project_id], t[:target_type], t[:action], "date(created_at + #{date_interval}) AS date", 'count(id) as total_amount') .select(t[:project_id], t[:target_type], t[:action], "date(created_at + #{date_interval}) AS date", 'count(id) as total_amount')
.group(t[:project_id], t[:target_type], t[:action], "date(created_at + #{date_interval})") .group(t[:project_id], t[:target_type], t[:action], "date(created_at + #{date_interval})")
.where(conditions) .where(conditions)
.having(t[:project_id].in(Arel::Nodes::SqlLiteral.new(authed_projects.to_sql))) .where("events.project_id in (#{authed_projects.to_sql})") # rubocop:disable GitlabSecurity/SqlInjection
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment