Skip to content

Commit

Permalink
Merge pull request #25 from openownership/fix-raw-records-performance
Browse files Browse the repository at this point in the history
Fix raw records performance
  • Loading branch information
spacesnottabs authored Aug 17, 2023
2 parents 6a0669c + 0b230a0 commit eb31dd7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
8 changes: 1 addition & 7 deletions app/controllers/entities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,7 @@ def show
@similar_people = entity.natural_person? ? similar_people(entity) : nil
end

raw_records = RAW_DATA_RECORD_REPOSITORY.all_for_entity(entity)
@data_source_names = DATA_SOURCE_REPOSITORY.data_source_names_for_raw_records(raw_records)

unless @data_source_names.empty?
@newest_raw_record = RAW_DATA_RECORD_REPOSITORY.newest_for_entity_date(entity)
@raw_record_count = raw_records.size
end
@data_source_names = DATA_SOURCE_REPOSITORY.data_source_names_for_entity(entity)

# Conversion
@oc_data = get_opencorporates_company_hash(entity, sparse: true) || {}
Expand Down
7 changes: 7 additions & 0 deletions app/repositories/data_source_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ def where_overview_present
all.filter { |data_source| data_source.overview.present? }
end

def data_source_names_for_entity(entity)
[
entity.relationships_as_source,
entity.relationships_as_target
].flatten.compact.map(&:provenance).map(&:source_name).uniq.sort
end

def data_source_names_for_raw_records(raw_records)
datasource_names = raw_records.map do |raw_record|
case raw_record
Expand Down
4 changes: 1 addition & 3 deletions app/views/entities/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,8 @@
%ul
%li
%p= @data_source_names.to_sentence
%p.meta-secondary
= t('entities.provenance.latest_data', date: @newest_raw_record.to_date)
%li
= link_to(t('entities.provenance.detail', count: @raw_record_count), raw_entity_path(@sentity.id))
= link_to(t('entities.provenance.detail'), raw_entity_path(@sentity.id))


- if @oc_data[:restricted_for_marketing]
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ en:
latest_data: 'Latest data: %{date}'
detail:
one: 'See the original source record'
other: 'See the %{count} original source records'
other: 'See the original source records'
data_sources:
show:
data_availability_title: Data availability and license
Expand Down

0 comments on commit eb31dd7

Please sign in to comment.