Skip to content

Commit

Permalink
7210-client-search-performance
Browse files Browse the repository at this point in the history
  • Loading branch information
ttoomey committed Feb 6, 2025
1 parent 0c6427f commit e1385b6
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/models/grda_warehouse/source_client_name_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SourceClientNameSet
include Enumerable

SourceClientName = Struct.new(:ds_name, :ds_id, :value, keyword_init: true) do
def to_s = value
def to_str = value
end
private_constant :SourceClientName

Expand Down
10 changes: 4 additions & 6 deletions app/models/grda_warehouse/source_client_view_accessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ def inspect
# @param user [User] The current user accessing the client data
# @param clients [Array<DestinationClient>] Collection of destination clients to load data for
# @raise [RuntimeError] if a destination client reference is missing
def initialize(user:, clients:)
def initialize(user:)
@user = user
@source_clients = {}

preload_source_clients(clients)
end

# Retrieves source clients for a given destination client
# @param client [DestinationClient] The destination client to look up
# @return [Array<HudClient>] Array of source client records associated with the destination client
def source_clients(client)
@source_clients[client.id] || []
key = client.id
preload_source_clients([client]) unless @source_clients.key?(key)
@source_clients[key] || []
end

# @param client [DestinationClient] The destination client to get names for
Expand All @@ -34,8 +34,6 @@ def client_names(client)
)
end

protected

def preload_source_clients(clients)
destination_client_ids = clients.map(&:id)
source_client_ids = GrdaWarehouse::WarehouseClient.where(destination_id: destination_client_ids).pluck(:source_id)
Expand Down
11 changes: 9 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,14 @@ def unique_role_names
end
end

def source_client_view_accessor(clients)
GrdaWarehouse::SourceClientViewAccessor.new(user: self, clients: clients)
# View helper for performant access to client details
# clients can be preloaded example:
# current_user.client_view_accessor.preload_source_clients(clients)
# clients.each do |client|
# puts current_user.client_view_accessor.source_clients(client).first
# end
#
def client_view_accessor
@client_view_accessor ||= GrdaWarehouse::SourceClientViewAccessor.new(user: self)
end
end
6 changes: 3 additions & 3 deletions app/views/assigned/clients/_client_table.haml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.o-page__main-content.mt-3
.clients__list
- accessor = current_user.source_client_view_accessor(clients)
- clients.each do |user_client|
- client = user_client.client
- source_clients = clients.map(&:user_client)
- accessor = current_user.client_view_accessor.preload_source_clients(source_clients)
- source_clients.each do |client|
- window_link = client.appropriate_path_for?(current_user)
- show_window_link = window_link.present?
- akas = accessor.client_names(client)
Expand Down
3 changes: 1 addition & 2 deletions app/views/clients/_aliases.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
- show_second_column = can_track_anomalies? || @client.alert_notes.exists?
-# this is a bit awkward as the API is shaped for a page of clients
- aliases = current_user.source_client_view_accessor([@client]).client_names(@client)
- aliases = current_user.client_view_accessor.client_names(@client)
- alias_class = if show_second_column then 'col-sm-9' else 'col' end
.row.flex-grow-1
%div{class: alias_class}
Expand Down
2 changes: 1 addition & 1 deletion app/views/clients/search/_aliases.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- akas = @accessor.client_names(client)
- akas = current_user.client_view_accessor.client_names(client)
- if akas.any?
.clients__client-additional-names
- akas.each do |aka|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
.o-page__main-content.mt-3
.clients__list
= render 'clients/new_client'
- @accessor = current_user.source_client_view_accessor(@clients)
- current_user.client_view_accessor.preload_source_clients(@clients)
- @clients.each do |client|
= render 'client_access_control/clients/client_card', client: client
= render 'common/pagination_bottom', item_name: 'client'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
:ruby
ssns = []
ages = []
@accessor.source_clients(client).each do |sc|

source_clients = current_user.client_view_accessor.source_clients(client)
source_clients.each do |sc|
pii = sc.pii_provider(user: current_user)
ssns.push(pii.ssn(force_mask: true))
ages.push(pii.dob_and_age(force_year_only: true))
Expand Down

0 comments on commit e1385b6

Please sign in to comment.