Method: Gitlab::Database::LoadBalancing::RackMiddleware#sticking_namespaces

Defined in:
lib/gitlab/database/load_balancing/rack_middleware.rb

#sticking_namespaces(env) ⇒ Object

Determines the sticking namespace and identifier based on the Rack environment.

For Rails requests this uses warden, but Grape and others have to manually set the right environment variable.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/gitlab/database/load_balancing/rack_middleware.rb', line 66

def sticking_namespaces(env)
  warden = env['warden']

  if warden && warden.user
    # When sticking per user, _only_ sticking the main connection could
    # result in the application trying to read data from a different
    # connection, while that data isn't available yet.
    #
    # To prevent this from happening, we scope sticking to all the
    # models that support load balancing. In the future (if we
    # determined this to be OK) we may be able to relax this.
    ::Gitlab::Database::LoadBalancing.base_models.map do |model|
      [model.sticking, :user, warden.user.id]
    end
  elsif env[STICK_OBJECT].present?
    env[STICK_OBJECT].to_a
  else
    []
  end
end