Class: User::InstancePreloadService

Inherits:
Object
  • Object
show all
Defined in:
app/services/user/instance_preload_service.rb

Overview

Preloads the instances for given users.

Instance Method Summary collapse

Constructor Details

#initialize(user_ids) ⇒ InstancePreloadService

Returns a new instance of InstancePreloadService


5
6
7
8
9
10
# File 'app/services/user/instance_preload_service.rb', line 5

def initialize(user_ids)
  ActsAsTenant.without_tenant do
    @instances = Instance.select('instances.*, instance_users.user_id AS user_id').joins(:instance_users).
                 where(instance_users: { user_id: user_ids }).order_by_name.group_by(&:user_id)
  end
end

Instance Method Details

#instances_for(user_id) ⇒ Array<Instance>|nil

Returns The instances, if found, else nil

Returns:

  • (Array<Instance>|nil)

    The instances, if found, else nil


13
14
15
# File 'app/services/user/instance_preload_service.rb', line 13

def instances_for(user_id)
  @instances[user_id]
end