Project

General

Profile

Patch #14318 » 0001-Fix-query-error-where-no-issue_ids-are-watched-or-fo.patch

Fix for postgresql empty list error - Frederico Camara, 2021-05-10 19:24

View differences:

app/models/issue.rb
136 136
            "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
137 137
          when 'own_watch'
138 138
            user_ids = [user.id] + user.groups.pluck(:id).compact
139
            "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}) OR #{table_name}.id IN (#{Watcher.where(user_id: user.id, watchable_type: 'Issue').pluck(:watchable_id).compact.join(',')}))"
139
            text_other_ids = Watcher.where(user_id: user.id, watchable_type: 'Issue').pluck(:watchable_id).compact.join(',')
140
            text_other_ids = "OR #{table_name}.id IN (#{text_other_ids})" if text_other_ids.present?
141
            "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}) #{text_other_ids})"
140 142
          when 'own_watch_contributed'
141 143
            user_ids = [user.id] + user.groups.pluck(:id).compact
142
            "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}) OR #{table_name}.id IN (#{Watcher.where(user_id: user.id, watchable_type: 'Issue').pluck(:watchable_id).compact.join(',')}) OR #{table_name}.id IN (#{Journal.where(user_id: user.id, journalized_type: 'Issue').group(:journalized_id).pluck(:journalized_id).compact.join(',')}))"
144
            text_other_ids = (Watcher.where(user_id: user.id, watchable_type: 'Issue').pluck(:watchable_id) + Journal.where(user_id: user.id, journalized_type: 'Issue').group(:journalized_id).pluck(:journalized_id)).compact.join(',')
145
            text_other_ids = "OR #{table_name}.id IN (#{text_other_ids})" if text_other_ids.present?
146
            "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}) #{text_other_ids})"
143 147
          else
144 148
              '1=0'
145 149
          end
(13-13/15)