From fa0be3f834b54bb276eb5233195181fa3760710f Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Mon, 16 Oct 2017 00:36:15 -0700 Subject: Add option to reduce motion (#5393) * Add option to reduce motion * Use HOC to wrap all Motion calls * fix case-sensitive issue * Avoid updating too frequently * Get rid of unnecessary change to _simple_status.html.haml --- app/lib/user_settings_decorator.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/lib') diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index cd4cf4b32..d48e1da65 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -23,6 +23,7 @@ class UserSettingsDecorator user.settings['boost_modal'] = boost_modal_preference if change?('setting_boost_modal') user.settings['delete_modal'] = delete_modal_preference if change?('setting_delete_modal') user.settings['auto_play_gif'] = auto_play_gif_preference if change?('setting_auto_play_gif') + user.settings['reduce_motion'] = reduce_motion_preference if change?('setting_reduce_motion') user.settings['system_font_ui'] = system_font_ui_preference if change?('setting_system_font_ui') user.settings['noindex'] = noindex_preference if change?('setting_noindex') user.settings['theme'] = theme_preference if change?('setting_theme') @@ -64,6 +65,10 @@ class UserSettingsDecorator boolean_cast_setting 'setting_auto_play_gif' end + def reduce_motion_preference + boolean_cast_setting 'setting_reduce_motion' + end + def noindex_preference boolean_cast_setting 'setting_noindex' end -- cgit From 6f490b4bfed5fba9bd543a4c99b5694f37cd1f99 Mon Sep 17 00:00:00 2001 From: unarist Date: Mon, 16 Oct 2017 22:58:23 +0900 Subject: Fix un-reblogged status being at wrong position in the home timeline (#5418) We've changed un-reblogging behavior when we implement Snowflake, to insert un-reblogged status at the position reblogging status existed. However, our API expects home timeline is ordered by status ids, and max_id/since_id filters by zset score. Due to this, un-reblogged status appears as a last item of result set, and timeline expansion may skips many statuses. So this reverts that change...reblogged status inserted at corresponding position to its id. --- app/lib/feed_manager.rb | 9 +++++---- spec/lib/feed_manager_spec.rb | 9 ++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'app/lib') diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index 89aeaadcd..dfd11a23b 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -198,10 +198,11 @@ class FeedManager # 2. Remove the reblogged status from the `:reblogs` zset. redis.zrem(reblog_key, status.reblog_of_id) - # 3. Add the reblogged status to the feed using the reblogging - # status' ID as its score, and the reblogged status' ID as its - # value. - redis.zadd(timeline_key, status.id, status.reblog_of_id) + # 3. Add the reblogged status to the feed. + # Note that we can't use old score in here + # and it must be an ID of corresponding status + # because we need to filter timeline by status ID. + redis.zadd(timeline_key, status.reblog_of_id, status.reblog_of_id) # 4. Remove the reblogging status from the feed (as normal) end diff --git a/spec/lib/feed_manager_spec.rb b/spec/lib/feed_manager_spec.rb index 923894ccb..643f1f003 100644 --- a/spec/lib/feed_manager_spec.rb +++ b/spec/lib/feed_manager_spec.rb @@ -233,19 +233,22 @@ RSpec.describe FeedManager do describe '#unpush' do it 'leaves a reblogged status when deleting the reblog' do account = Fabricate(:account) - reblogged = Fabricate(:status) + reblogged = Fabricate(:status, id: Mastodon::Snowflake.id_at(2.day.ago.utc)) + other_status = Fabricate(:status, id: Mastodon::Snowflake.id_at(1.day.ago.utc)) status = Fabricate(:status, reblog: reblogged) + FeedManager.instance.push('type', account, other_status) FeedManager.instance.push('type', account, status) # The reblogging status should show up under normal conditions. - expect(Redis.current.zrange("feed:type:#{account.id}", 0, -1)).to eq [status.id.to_s] + expect(Redis.current.zrange("feed:type:#{account.id}", 0, -1)).to eq [other_status.id.to_s, status.id.to_s] FeedManager.instance.unpush('type', account, status) # Because we couldn't tell if the status showed up any other way, # we had to stick the reblogged status in by itself. - expect(Redis.current.zrange("feed:type:#{account.id}", 0, -1)).to eq [reblogged.id.to_s] + # And it must be ordered by status ids. + expect(Redis.current.zrange("feed:type:#{account.id}", 0, -1)).to eq [reblogged.id.to_s, other_status.id.to_s] end it 'sends push updates' do -- cgit From 7cc71748cecfa6cb35bc53e656df39d6f9219ae2 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 16 Oct 2017 16:08:51 +0200 Subject: Ensure that feed renegeration restores non-zero items (#5409) Fix #5398 Ordering the home timeline query by account_id meant that the first 100 items belonged to a single account. There was also no reason to reverse-iterate over the statuses. Assuming the user accesses the feed halfway-through, it's better to have recent statuses already available at the top. Therefore working from newer->older is ideal. If the algorithm ends up filtering all items out during last-mile filtering, repeat again a page further. The algorithm terminates when either at least one item has been added, or if the database query returns nothing (end of data reached) --- app/lib/feed_manager.rb | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'app/lib') diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index dfd11a23b..cc19c1d1a 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -100,11 +100,24 @@ class FeedManager end def populate_feed(account) - prepopulate_limit = FeedManager::MAX_ITEMS / 4 - statuses = Status.as_home_timeline(account).order(account_id: :desc).limit(prepopulate_limit) - statuses.reverse_each do |status| - next if filter_from_home?(status, account) - add_to_feed(:home, account, status) + added = 0 + limit = FeedManager::MAX_ITEMS / 2 + max_id = nil + + loop do + statuses = Status.as_home_timeline(account) + .paginate_by_max_id(limit, max_id) + + break if statuses.empty? + + statuses.each do |status| + next if filter_from_home?(status, account) + added += 1 if add_to_feed(:home, account, status) + end + + break unless added.zero? + + max_id = statuses.last.id end end -- cgit From 34118169ace56b31d6d4b26638fb7375171b7796 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 16 Oct 2017 20:44:31 +0200 Subject: Keep references to all reblogs of a status on home feed (#5419) * Keep references to all reblogs of a status on home feed When inserting reblog: Add to set of reblogs of this status on the feed, if original status was present in the feed, add it to that set as well. When removing a reblog: Remove it from that set. Take random remaining item from the set. If one exists, re-insert it into feed, otherwise do not re-insert anything. Fix #4210 * When original is removed, toss out reblog references --- app/lib/feed_manager.rb | 28 ++++++++--- app/workers/scheduler/feed_cleanup_scheduler.rb | 5 +- spec/lib/feed_manager_spec.rb | 66 ++++++++++++++++++------- 3 files changed, 72 insertions(+), 27 deletions(-) (limited to 'app/lib') diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index cc19c1d1a..7f95d7784 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -174,13 +174,19 @@ class FeedManager # either action is appropriate. def add_to_feed(timeline_type, account, status) timeline_key = key(timeline_type, account.id) - reblog_key = key(timeline_type, account.id, 'reblogs') + reblog_key = key(timeline_type, account.id, 'reblogs') if status.reblog? + reblog_set_key = key(timeline_type, account.id, "reblogs:#{status.reblog_of_id}") + # If the original status or a reblog of it is within # REBLOG_FALLOFF statuses from the top, do not re-insert it into # the feed rank = redis.zrevrank(timeline_key, status.reblog_of_id) + + redis.sadd(reblog_set_key, status.reblog_of_id) unless rank.nil? + redis.sadd(reblog_set_key, status.id) + return false if !rank.nil? && rank < FeedManager::REBLOG_FALLOFF reblog_rank = redis.zrevrank(reblog_key, status.reblog_of_id) @@ -201,7 +207,7 @@ class FeedManager # do so if appropriate. def remove_from_feed(timeline_type, account, status) timeline_key = key(timeline_type, account.id) - reblog_key = key(timeline_type, account.id, 'reblogs') + reblog_key = key(timeline_type, account.id, 'reblogs') if status.reblog? # 1. If the reblogging status is not in the feed, stop. @@ -211,13 +217,21 @@ class FeedManager # 2. Remove the reblogged status from the `:reblogs` zset. redis.zrem(reblog_key, status.reblog_of_id) - # 3. Add the reblogged status to the feed. - # Note that we can't use old score in here - # and it must be an ID of corresponding status - # because we need to filter timeline by status ID. - redis.zadd(timeline_key, status.reblog_of_id, status.reblog_of_id) + # 3. Remove reblog from set of this status's reblogs, and + # re-insert another reblog or original into the feed if + # one remains in the set + reblog_set_key = key(timeline_type, account.id, "reblogs:#{status.reblog_of_id}") + + redis.srem(reblog_set_key, status.id) + other_reblog = redis.srandmember(reblog_set_key) + + redis.zadd(timeline_key, other_reblog, other_reblog) if other_reblog # 4. Remove the reblogging status from the feed (as normal) + # (outside conditional) + else + # If the original is getting deleted, no use for reblog references + redis.del(key(timeline_type, account.id, "reblogs:#{status.id}")) end redis.zrem(timeline_key, status.id) diff --git a/app/workers/scheduler/feed_cleanup_scheduler.rb b/app/workers/scheduler/feed_cleanup_scheduler.rb index dbebaa2c3..222f5ed84 100644 --- a/app/workers/scheduler/feed_cleanup_scheduler.rb +++ b/app/workers/scheduler/feed_cleanup_scheduler.rb @@ -6,8 +6,9 @@ class Scheduler::FeedCleanupScheduler def perform redis.pipelined do - inactive_users.pluck(:account_id).each do |account_id| + inactive_users.each do |account_id| redis.del(FeedManager.instance.key(:home, account_id)) + redis.del(FeedManager.instance.key(:home, account_id, 'reblogs')) end end end @@ -15,7 +16,7 @@ class Scheduler::FeedCleanupScheduler private def inactive_users - User.confirmed.inactive + @inactive_users ||= User.confirmed.inactive.pluck(:account_id) end def redis diff --git a/spec/lib/feed_manager_spec.rb b/spec/lib/feed_manager_spec.rb index 643f1f003..454c3afec 100644 --- a/spec/lib/feed_manager_spec.rb +++ b/spec/lib/feed_manager_spec.rb @@ -231,36 +231,66 @@ RSpec.describe FeedManager do end describe '#unpush' do - it 'leaves a reblogged status when deleting the reblog' do - account = Fabricate(:account) - reblogged = Fabricate(:status, id: Mastodon::Snowflake.id_at(2.day.ago.utc)) - other_status = Fabricate(:status, id: Mastodon::Snowflake.id_at(1.day.ago.utc)) - status = Fabricate(:status, reblog: reblogged) + let(:receiver) { Fabricate(:account) } - FeedManager.instance.push('type', account, other_status) - FeedManager.instance.push('type', account, status) + it 'leaves a reblogged status if original was on feed' do + reblogged = Fabricate(:status) + status = Fabricate(:status, reblog: reblogged) + + FeedManager.instance.push('type', receiver, reblogged) + FeedManager::REBLOG_FALLOFF.times { FeedManager.instance.push('type', receiver, Fabricate(:status)) } + FeedManager.instance.push('type', receiver, status) # The reblogging status should show up under normal conditions. - expect(Redis.current.zrange("feed:type:#{account.id}", 0, -1)).to eq [other_status.id.to_s, status.id.to_s] + expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to include(status.id.to_s) - FeedManager.instance.unpush('type', account, status) + FeedManager.instance.unpush('type', receiver, status) - # Because we couldn't tell if the status showed up any other way, - # we had to stick the reblogged status in by itself. - # And it must be ordered by status ids. - expect(Redis.current.zrange("feed:type:#{account.id}", 0, -1)).to eq [reblogged.id.to_s, other_status.id.to_s] + # Restore original status + expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to_not include(status.id.to_s) + expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to include(reblogged.id.to_s) + end + + it 'removes a reblogged status if it was only reblogged once' do + reblogged = Fabricate(:status) + status = Fabricate(:status, reblog: reblogged) + + FeedManager.instance.push('type', receiver, status) + + # The reblogging status should show up under normal conditions. + expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to eq [status.id.to_s] + + FeedManager.instance.unpush('type', receiver, status) + + expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to be_empty + end + + it 'leaves a reblogged status if another reblog was in feed' do + reblogged = Fabricate(:status) + status = Fabricate(:status, reblog: reblogged) + another_status = Fabricate(:status, reblog: reblogged) + + FeedManager.instance.push('type', receiver, status) + FeedManager.instance.push('type', receiver, another_status) + + # The reblogging status should show up under normal conditions. + expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to eq [status.id.to_s] + + FeedManager.instance.unpush('type', receiver, status) + + expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to eq [another_status.id.to_s] end it 'sends push updates' do - account = Fabricate(:account) - status = Fabricate(:status) - FeedManager.instance.push('type', account, status) + status = Fabricate(:status) + + FeedManager.instance.push('type', receiver, status) allow(Redis.current).to receive_messages(publish: nil) - FeedManager.instance.unpush('type', account, status) + FeedManager.instance.unpush('type', receiver, status) deletion = Oj.dump(event: :delete, payload: status.id.to_s) - expect(Redis.current).to have_received(:publish).with("timeline:#{account.id}", deletion) + expect(Redis.current).to have_received(:publish).with("timeline:#{receiver.id}", deletion) end end end -- cgit