Opt out of writer affinity on readings controller
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
include Authentication, CurrentTimezone, SetPlatform
|
||||
include Authentication, CurrentTimezone, SetPlatform, WriterAffinity
|
||||
|
||||
stale_when_importmap_changes
|
||||
allow_browser versions: :modern
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
class Cards::ReadingsController < ApplicationController
|
||||
include CardScoped
|
||||
|
||||
skip_writer_affinity
|
||||
|
||||
def create
|
||||
@notifications = @card.read_by(Current.user)
|
||||
end
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
module WriterAffinity
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def skip_writer_affinity(**)
|
||||
before_action :set_writer_affinity_opt_out_header, **
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def set_writer_affinity_opt_out_header
|
||||
response.headers["X-Writer-Affinity"] = "false"
|
||||
end
|
||||
end
|
||||
@@ -22,4 +22,10 @@ class Cards::ReadingsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "create opts-out of writer affinity in the load balancer" do
|
||||
post card_reading_path(cards(:logo)), as: :turbo_stream
|
||||
|
||||
assert_equal "false", response.headers["X-Writer-Affinity"]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user