]> cat aescling's git repositories - mastodon.git/commitdiff
Only call regeneration worker after first login after a 14 day break
authorEugen Rochko <eugen@zeonfederated.com>
Tue, 4 Apr 2017 00:00:10 +0000 (02:00 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Tue, 4 Apr 2017 00:00:10 +0000 (02:00 +0200)
app/controllers/application_controller.rb
app/controllers/oauth/authorizations_controller.rb
app/models/feed.rb
app/workers/regeneration_worker.rb

index ef9364897c911ded164cba8454fa2a5e7b7acd12..c06142fd43ac211fc597f15038186524d5e18b88 100644 (file)
@@ -39,7 +39,14 @@ class ApplicationController < ActionController::Base
   end
 
   def set_user_activity
-    current_user.touch(:current_sign_in_at) if !current_user.nil? && (current_user.current_sign_in_at.nil? || current_user.current_sign_in_at < 24.hours.ago)
+    return unless !current_user.nil? && (current_user.current_sign_in_at.nil? || current_user.current_sign_in_at < 24.hours.ago)
+
+    # Mark user as signed-in today
+    current_user.update_tracked_fields(request)
+
+    # If the sign in is after a two week break, we need to regenerate their feed
+    RegenerationWorker.perform_async(current_user.account_id) if current_user.last_sign_in_at < 14.days.ago
+    return
   end
 
   def check_suspension
index feaad04f6b6543a63702b5dbc56b4cb868f4707d..7c25266d81356fe66881c6bbf52e4284682a1bae 100644 (file)
@@ -3,6 +3,7 @@
 class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController
   skip_before_action :authenticate_resource_owner!
 
+  before_action :set_locale
   before_action :store_current_location
   before_action :authenticate_resource_owner!
 
@@ -11,4 +12,10 @@ class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController
   def store_current_location
     store_location_for(:user, request.url)
   end
+
+  def set_locale
+    I18n.locale = current_user.try(:locale) || I18n.default_locale
+  rescue I18n::InvalidLocale
+    I18n.locale = I18n.default_locale
+  end
 end
index 5e1905e15244be8332f7257d714460c43fd40cf0..3cbc160a06d1e87cd37c9d21113c3d73cae8c5ac 100644 (file)
@@ -10,17 +10,9 @@ class Feed
     max_id     = '+inf' if max_id.blank?
     since_id   = '-inf' if since_id.blank?
     unhydrated = redis.zrevrangebyscore(key, "(#{max_id}", "(#{since_id}", limit: [0, limit], with_scores: true).map(&:last).map(&:to_i)
+    status_map = Status.where(id: unhydrated).cache_ids.map { |s| [s.id, s] }.to_h
 
-    # If we're after most recent items and none are there, we need to precompute the feed
-    if unhydrated.empty? && max_id == '+inf' && since_id == '-inf'
-      RegenerationWorker.perform_async(@account.id, @type)
-      @statuses = Status.send("as_#{@type}_timeline", @account).cache_ids.paginate_by_max_id(limit, nil, nil)
-    else
-      status_map = Status.where(id: unhydrated).cache_ids.map { |s| [s.id, s] }.to_h
-      @statuses  = unhydrated.map { |id| status_map[id] }.compact
-    end
-
-    @statuses
+    unhydrated.map { |id| status_map[id] }.compact
   end
 
   private
index 289b63d84a375d3d1ca75fae3c93c15e94fa19b8..82665b581f91a06c55731cac35cca17f9fbd7f77 100644 (file)
@@ -5,7 +5,7 @@ class RegenerationWorker
 
   sidekiq_options queue: 'pull', backtrace: true
 
-  def perform(account_id, timeline_type)
-    PrecomputeFeedService.new.call(timeline_type, Account.find(account_id))
+  def perform(account_id, _ = :home)
+    PrecomputeFeedService.new.call(:home, Account.find(account_id))
   end
 end