From 385372e3848eb797878023a650a7ef5e651e6410 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 20 Nov 2017 11:49:09 +0800 Subject: [PATCH] Revert "PERF: Reduce number of topics to filter while querying for unread." This reverts commit c06b782cabbde812350622ee4728dc61dc524d2f. --- lib/topic_query.rb | 20 ++------------------ spec/components/topic_query_spec.rb | 22 ++++------------------ 2 files changed, 6 insertions(+), 36 deletions(-) diff --git a/lib/topic_query.rb b/lib/topic_query.rb index 2da99393a02..14aaaa8bbc7 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -288,9 +288,8 @@ class TopicQuery list .where("tu.last_read_post_number < topics.#{col_name}") - .where("tu.notification_level >= :tracking", - tracking: TopicUser.notification_levels[:tracking] - ) + .where("COALESCE(tu.notification_level, :regular) >= :tracking", + regular: TopicUser.notification_levels[:regular], tracking: TopicUser.notification_levels[:tracking]) end def prioritize_pinned_topics(topics, options) @@ -370,10 +369,6 @@ class TopicQuery result end - def unread_results_redis_key - "last_unread_result_bumped_at:#{@user.id}" - end - def unread_results(options = {}) result = TopicQuery.unread_filter( default_results(options.reverse_merge(unordered: true)), @@ -385,17 +380,6 @@ class TopicQuery result = filter_callback.call(:unread, result, @user, options) end - if !(last_bumped_at = $redis.get(unread_results_redis_key)) - last_bumped_at = result.unscope(:limit, :order).order(:bumped_at).first&.bumped_at - - $redis.setex( - unread_results_redis_key, - 1.hour.to_i, - (last_bumped_at || Time.zone.now).to_s - ) - end - - result = result.where("topics.bumped_at >= ?", last_bumped_at) if last_bumped_at suggested_ordering(result, options) end diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index d2a1c28ca32..be119f53099 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -443,9 +443,6 @@ describe TopicQuery do end context 'unread / read topics' do - after do - $redis.flushall - end context 'with no data' do it "has no unread topics" do @@ -487,15 +484,10 @@ describe TopicQuery do context 'list_unread' do it 'lists topics correctly' do - freeze_time do - new_topic = Fabricate(:post, user: creator).topic + new_topic = Fabricate(:post, user: creator).topic - expect(topic_query.list_unread.topics).to eq([]) - expect(topic_query.list_read.topics).to match_array([fully_read, partially_read]) - - expect($redis.get(topic_query.unread_results_redis_key)) - .to eq(Time.zone.now.to_s) - end + expect(topic_query.list_unread.topics).to eq([]) + expect(topic_query.list_read.topics).to match_array([fully_read, partially_read]) end end @@ -503,16 +495,10 @@ describe TopicQuery do before do user.user_option.auto_track_topics_after_msecs = 0 user.user_option.save - partially_read.update!(bumped_at: 2.days.ago) end it 'only contains the partially read topic' do - freeze_time do - expect(topic_query.list_unread.topics).to eq([partially_read]) - - expect($redis.get(topic_query.unread_results_redis_key)) - .to eq(partially_read.bumped_at.to_s) - end + expect(topic_query.list_unread.topics).to eq([partially_read]) end end