Skip to content

Commit

Permalink
load_async still got error after Rails 7.1.3 (#1400)
Browse files Browse the repository at this point in the history
* Add integration test to cover error case.

* Load async also not working.
  • Loading branch information
Eric-Guo authored Jan 18, 2024
1 parent 13a2e9a commit 1e8b1a5
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TopicsController < ApplicationController
def index
@suggest_topics = []
if params[:page].to_i <= 1
@suggest_topics = topics_scope.suggest.includes(:node).limit(3).load_async
@suggest_topics = topics_scope.suggest.includes(:node).limit(3)
end
@topics = topics_scope.without_suggest.last_actived.includes(:node).page(params[:page])
@page_title = t("menu.topics")
Expand Down Expand Up @@ -49,7 +49,7 @@ def show
@show_raw = params[:raw] == "1"
@can_reply = can?(:create, Reply)

@replies = Reply.unscoped.where(topic_id: @topic.id).order(:id).all.load_async
@replies = Reply.unscoped.where(topic_id: @topic.id).order(:id).all
@user_like_reply_ids = current_user&.like_reply_ids_by_replies(@replies) || []

@has_followed = current_user&.follow_topic?(@topic)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/user_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def only_user!
end

def user_show
@replies = @user.replies.without_system.fields_for_list.recent.includes(:topic).limit(10).load_async
@replies = @user.replies.without_system.fields_for_list.recent.includes(:topic).limit(10)
@topics = @user.topics.fields_for_list.high_likes.page(params[:page])
end
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def index
else
@counters.where(key: :yearly_replies_count)
end
@counters = @counters.load_async

@active_users = @counters.includes(:countable).order("value desc").limit(100).map(&:countable)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ def method_missing(method, *args, &block)
def self.active_users(limit: 32)
counter_scope = where(countable_type: "User")
counter_scope = counter_scope.where(key: :monthly_replies_count)
counter_scope.includes(:countable).order("value desc").limit(limit).load_async.map(&:countable)
counter_scope.includes(:countable).order("value desc").limit(limit).map(&:countable)
end
end
6 changes: 3 additions & 3 deletions app/views/topics/_references.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= cache([@topic, "reference_topics"]) do %>
<%
@reference_topics = @topic.reference_topics.load_async
@reference_by_topics = @topic.reference_by_topics.load_async
@reference_topics = @topic.reference_topics
@reference_by_topics = @topic.reference_by_topics
%>
<% if @reference_topics.length > 0 || @reference_by_topics.length > 0 %>
<div class="mb-4 topic-references card">
Expand Down Expand Up @@ -31,4 +31,4 @@
</div>
</div>
<% end %>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/users/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
</div>
</div>
<% if Setting.has_module?(:team) %>
<% @user_teams = @user.teams.load_async %>
<% @user_teams = @user.teams %>
<% if !@user_teams.blank? %>
<div class="mb-4 card user-teams">
<div class="card-body">
Expand Down
8 changes: 8 additions & 0 deletions test/integration/users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ class UsersTest < ActionDispatch::IntegrationTest
assert_equal 200, response.status
end
end

test "should get user list" do
%w[foo foo1 1234 foo-bar foo_bar foo_ foo.bar].each do |login|
create(:user, login: login)
get "/users"
assert_response :success
end
end
end

0 comments on commit 1e8b1a5

Please sign in to comment.