Skip to content

Commit

Permalink
Remove Rails 6.0.0.rc2 workaround
Browse files Browse the repository at this point in the history
This was a work-around for:
rails/rails#36761

It is no longer necessary and won't work with Rails 6.0.0
  • Loading branch information
glebm committed Aug 17, 2019
1 parent 7bb3791 commit e0dd726
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
7 changes: 1 addition & 6 deletions app/models/concerns/thredded/topic_common.rb
Expand Up @@ -62,12 +62,7 @@ def unread(user)

unread_scope = reads_class.where(reads[:id].eq(nil).or(reads[:unread_posts_count].not_eq(0)))

# Work around https://github.com/rails/rails/issues/36761
if Thredded.rails_gte_600_rc_2?
merge(unread_scope).joins(joins_reads)
else
joins(joins_reads).merge(unread_scope)
end
joins(joins_reads).merge(unread_scope)
end

private
Expand Down
18 changes: 3 additions & 15 deletions app/models/thredded/messageboard.rb
Expand Up @@ -138,21 +138,9 @@ def unread_topics_counts(user:, topics_scope: Thredded::Topic.all)
.and(read_states[:user_id].eq(user.id))
.and(read_states[:unread_posts_count].eq(0))

scope =
# Work around https://github.com/rails/rails/issues/36761
if Thredded.rails_gte_600_rc_2?
merge(topics_scope).joins(
messageboards.join(topics)
.on(topics[:messageboard_id].eq(messageboards[:id]))
.outer_join(read_states).on(read_states_join_cond).join_sources
)
else
joins(:topics).merge(topics_scope).joins(
messageboards.outer_join(read_states).on(read_states_join_cond).join_sources
)
end

scope.group(messageboards[:id]).pluck(
joins(:topics).merge(topics_scope).joins(
messageboards.outer_join(read_states).on(read_states_join_cond).join_sources
).group(messageboards[:id]).pluck(
:id,
Arel::Nodes::Subtraction.new(topics[:id].count, read_states[:id].count)
).to_h
Expand Down
7 changes: 0 additions & 7 deletions lib/thredded.rb
Expand Up @@ -254,13 +254,6 @@ def rails_gte_51?
@rails_gte_51
end

# @api private
# Mainly to work around https://github.com/rails/rails/issues/36761
def rails_gte_600_rc_2?
@rails_gte_600_rc_2 = (Rails.gem_version >= Gem::Version.new('6.0.0.rc2')) if @rails_gte_600_rc_2.nil?
@rails_gte_600_rc_2
end

# @api private
def rails_supports_csp_nonce?
@rails_supports_csp_nonce = (Rails.gem_version >= Gem::Version.new('5.2.0')) if @rails_supports_csp_nonce.nil?
Expand Down

0 comments on commit e0dd726

Please sign in to comment.