FIX: Don't update `User#last_seen_at` when PG is in readonly take 3.

FIX: Don’t update User#last_seen_at when PG is in readonly take 3.

diff --git a/lib/auth/default_current_user_provider.rb b/lib/auth/default_current_user_provider.rb
index a01e70f..7f1bf24 100644
--- a/lib/auth/default_current_user_provider.rb
+++ b/lib/auth/default_current_user_provider.rb
@@ -241,6 +241,8 @@ class Auth::DefaultCurrentUserProvider
   end
 
   def should_update_last_seen?
+    return false if Discourse.pg_readonly_mode?
+
     if @request.xhr?
       @env["HTTP_DISCOURSE_VISIBLE".freeze] == "true".freeze
     elsif !!(@env[API_KEY_ENV]) || !!(@env[USER_API_KEY_ENV])
diff --git a/spec/components/auth/default_current_user_provider_spec.rb b/spec/components/auth/default_current_user_provider_spec.rb
index 4101a42..8e3f5b6 100644
--- a/spec/components/auth/default_current_user_provider_spec.rb
+++ b/spec/components/auth/default_current_user_provider_spec.rb
@@ -161,17 +161,20 @@ describe Auth::DefaultCurrentUserProvider do
   end
 
   describe "#current_user" do
+    let(:user) { Fabricate(:user) }
+
+    let(:unhashed_token) do
+      new_provider = provider('/')
+      cookies = {}
+      new_provider.log_on_user(user, {}, cookies)
+      cookies["_t"][:value]
+    end
+
     after do
       $redis.flushall
     end
 
     it "should not update last seen for suspended users" do
-      provider = provider('/')
-      user = Fabricate(:user)
-      cookies = {}
-      provider.log_on_user(user, {}, cookies)
-      unhashed_token = cookies["_t"][:value]
-
       freeze_time
 
       provider2 = provider("/", "HTTP_COOKIE" => "_t=#{unhashed_token}")
@@ -192,6 +195,23 @@ describe Auth::DefaultCurrentUserProvider do
       u.reload
       expect(u.last_seen_at).to eq(nil)
     end
+
+    describe "when readonly mode is enabled due to postgres" do
+      before do
+        Discourse.enable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
+      end
+
+       after do
+        Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
+      end
+
+      it "should not update last seen at" do
+        provider2 = provider("/", "HTTP_COOKIE" => "_t=#{unhashed_token}")
+        u = provider2.current_user
+        u.reload
+        expect(u.last_seen_at).to eq(nil)
+      end
+    end
   end
 
   it "should update ajax reqs with discourse visible" do

GitHub sha: d3290029