potential fix for #2192

This commit is contained in:
r888888888
2014-06-12 21:41:37 -07:00
parent 79d8778051
commit 58a0086e69
3 changed files with 22 additions and 2 deletions

View File

@@ -17,7 +17,6 @@ class ForumTopicsController < ApplicationController
end
def index
# session[:read_forum_topics] = ""
@query = ForumTopic.active.search(params[:search])
@forum_topics = @query.order("is_sticky DESC, updated_at DESC").paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
@read_forum_topic_ids = read_forum_topic_ids

View File

@@ -124,9 +124,11 @@ class ForumTopic < ActiveRecord::Base
end
hash[id.to_s] = updated_at.to_i.to_s
result = hash.to_a.flatten.join(" ")
if result.size > 3000
while result.size > 3000
ids = result.scan(/\S+/)
print "slicing from #{result.size} to "
result = ids[(ids.size / 2)..-1].join(" ")
puts result.size
end
update_last_forum_read_at(hash.keys)
result

View File

@@ -16,6 +16,25 @@ class ForumTopicsControllerTest < ActionController::TestCase
CurrentUser.ip_addr = nil
end
context "show action" do
should "render" do
get :show, {:id => @forum_topic.id}
assert_response :success
end
context "when the read_forum_topics session exceeds the maximum cookie size" do
setup do
@cookie_data = 1.upto(10_000).to_a.join(" ")
end
should "truncate" do
get :show, {:id => @forum_topic.id}, {:user_id => @user.id, :read_forum_topics => @cookie_data}
assert_response :success
assert_equal(1570, session[:read_forum_topics].size)
end
end
end
context "index action" do
should "list all forum topics" do
get :index