fix: force build_contact and increment_view_count methods to use writing role
These methods are used by the widget to create a contact and helpcenter to increment the view count. Since these methods are triggered by GET request, Rails will use the reading role which will fail if the table is readonly.
This commit is contained in:
@@ -47,8 +47,10 @@ class WidgetsController < ActionController::Base
|
||||
def build_contact
|
||||
return if @contact.present?
|
||||
|
||||
@contact_inbox, @token = build_contact_inbox_with_token(@web_widget, additional_attributes)
|
||||
@contact = @contact_inbox.contact
|
||||
ActiveRecord::Base.connected_to(role: :writing) do
|
||||
@contact_inbox, @token = build_contact_inbox_with_token(@web_widget, additional_attributes)
|
||||
@contact = @contact_inbox.contact
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_account_is_active
|
||||
|
||||
@@ -114,8 +114,10 @@ class Article < ApplicationRecord
|
||||
|
||||
def increment_view_count
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
update_column(:views, views? ? views + 1 : 1)
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
ActiveRecord::Base.connected_to(role: :writing) do
|
||||
update_column(:views, views? ? views + 1 : 1)
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
end
|
||||
end
|
||||
|
||||
def self.update_positions(positions_hash)
|
||||
|
||||
@@ -70,6 +70,10 @@ Rails.application.configure do
|
||||
# require 'syslog/logger'
|
||||
config.logger = ActiveSupport::Logger.new(Rails.root.join('log', "#{Rails.env}.log"), 1, ENV.fetch('LOG_SIZE', '1024').to_i.megabytes)
|
||||
|
||||
config.active_record.database_selector = { delay: 2.seconds }
|
||||
config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
|
||||
config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
|
||||
|
||||
# Bullet configuration to fix the N+1 queries
|
||||
config.after_initialize do
|
||||
Bullet.enable = true
|
||||
|
||||
Reference in New Issue
Block a user