Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release-1.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacug committed Oct 4, 2022
2 parents fe3dd5e + cc897fa commit c5fe07c
Show file tree
Hide file tree
Showing 15 changed files with 433 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.9.0

* Add parameter to taxon concept show API internal endpoint to trimmed response for the mobile app

### 1.8.6

* Schedule rebuild job to run daily on staging
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/taxon_concepts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def show
s = Species::ShowTaxonConceptSerializerCites
end
render :json => @taxon_concept,
:serializer => s
:serializer => s, :trimmed => params[:trimmed]
end

protected
Expand Down
4 changes: 2 additions & 2 deletions app/models/species/taxon_concept_prefix_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def initialize_query
end

@query = @query.
select('id, full_name, rank_name, name_status,
select('id, full_name, rank_name, name_status, author_year,
ARRAY_AGG_NOTNULL(
DISTINCT CASE
WHEN matched_name != full_name THEN matched_name ELSE NULL
Expand All @@ -85,7 +85,7 @@ def initialize_query
rank_display_name_en, rank_display_name_es, rank_display_name_fr').
where(type_of_match: types_of_match).
group([
:id, :full_name, :rank_name, :name_status, :rank_order,
:id, :full_name, :rank_name, :name_status, :author_year, :rank_order,
:rank_display_name_en, :rank_display_name_es, :rank_display_name_fr
])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Species::AutocompleteTaxonConceptSerializer < ActiveModel::Serializer
attributes :id, :full_name, :rank_name, :name_status, :matching_names
attributes :id, :full_name, :author_year, :rank_name, :name_status, :matching_names

def rank_name
rank_with_locale = "rank_display_name_#{I18n.locale.to_s}"
Expand Down
15 changes: 15 additions & 0 deletions app/serializers/species/cites_listing_change_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ class Species::CitesListingChangeSerializer < Species::ListingChangeSerializer
:hash_full_note_en, :hash_display,
:nomenclature_note_en, :nomenclature_note_fr, :nomenclature_note_es

def include_is_addition?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_nomenclature_note_fr?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_nomenclature_note_es?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def change_type
if object.change_type_name == ChangeType::RESERVATION_WITHDRAWAL
"w"
Expand Down
15 changes: 13 additions & 2 deletions app/serializers/species/cites_suspension_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,21 @@ class Species::CitesSuspensionSerializer < ActiveModel::Serializer
:start_notification

def geo_entity
object['geo_entity_en']
@options[:trimmed] == 'true' ? object['geo_entity_en'].slice('iso_code2') : object['geo_entity_en']
end

def start_notification
object['start_notification']
@options[:trimmed] == 'true' ? object['start_notification'].except('date') : object['start_notification']
end

def include_nomenclature_note_fr?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_nomenclature_note_es?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

end
30 changes: 25 additions & 5 deletions app/serializers/species/eu_decision_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,48 @@ class Species::EuDecisionSerializer < ActiveModel::Serializer
:private_url,
:intersessional_decision_id

def include_nomenclature_note_fr?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_nomenclature_note_es?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_private_url?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_intersessional_decision_id?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def eu_decision_type
object['eu_decision_type']
@options[:trimmed] == 'true' ? object['eu_decision_type'].slice('name') : object['eu_decision_type']
end

def srg_history
object['srg_history']
@options[:trimmed] == 'true' ? object['srg_history'].except('description') : object['srg_history']
end

def geo_entity
object['geo_entity_en']
@options[:trimmed] == 'true' ? object['geo_entity_en'].slice('iso_code2') : object['geo_entity_en']
end

def start_event
object['start_event']
@options[:trimmed] == 'true' ? object['start_event'].except('date') : object['start_event']
end

def source
object['source_en']
end

def term
object['term_en']
@options[:trimmed] == 'true' ? object['term_en'].slice('name') : object['term_en']
end

def private_url
Expand Down
15 changes: 15 additions & 0 deletions app/serializers/species/eu_listing_change_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ class Species::EuListingChangeSerializer < Species::ListingChangeSerializer
:hash_full_note_en, :hash_display,
:nomenclature_note_en, :nomenclature_note_fr, :nomenclature_note_es

def include_change_type_class?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_nomenclature_note_fr?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_nomenclature_note_es?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def change_type
if object.change_type_name == ChangeType::RESERVATION_WITHDRAWAL
"w"
Expand Down
17 changes: 16 additions & 1 deletion app/serializers/species/quota_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,23 @@ class Species::QuotaSerializer < ActiveModel::Serializer
:geo_entity,
:unit

def include_nomenclature_note_fr?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_nomenclature_note_es?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_publication_date_formatted?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def geo_entity
object['geo_entity_en']
@options[:trimmed] == 'true' ? object['geo_entity_en'].slice('iso_code2') : object['geo_entity_en']
end

def unit
Expand Down
49 changes: 46 additions & 3 deletions app/serializers/species/show_taxon_concept_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,41 @@ class Species::ShowTaxonConceptSerializer < ActiveModel::Serializer
has_many :taxon_concept_references, :serializer => Species::ReferenceSerializer,
:key => :references

def include_parent_id?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_nomenclature_notification?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_subspecies?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_kingdom_name?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_species_name?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_rank_name?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_name_status?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def rank_name
object.data['rank_name']
end
Expand Down Expand Up @@ -90,7 +125,14 @@ def distributions_with_tags_and_references
end

def distributions
distributions_with_tags_and_references
@options[:trimmed] == 'true' ? distributions_with_tags_and_references_trimmed : distributions_with_tags_and_references
end

def distributions_with_tags_and_references_trimmed
Distribution.from('api_distributions_view distributions').
where(taxon_concept_id: object.id).
select("iso_code2, ARRAY_TO_STRING(tags, ',') AS tags_list").
order('iso_code2').all
end

def subspecies
Expand All @@ -105,7 +147,7 @@ def standard_references
end

def distribution_references
distributions_with_tags_and_references
@options[:trimmed] == 'true' ? distributions_with_tags_and_references_trimmed : distributions_with_tags_and_references
end

def cache_key
Expand All @@ -115,7 +157,8 @@ def cache_key
object.updated_at,
object.dependents_updated_at,
object.m_taxon_concept.try(:updated_at) || "",
scope.current_user ? true : false
scope.current_user ? true : false,
@options[:trimmed] == 'true' ? true : false
]
Rails.logger.debug "CACHE KEY: #{key.inspect}"
key
Expand Down
25 changes: 25 additions & 0 deletions app/serializers/species/show_taxon_concept_serializer_cites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@ class Species::ShowTaxonConceptSerializerCites < Species::ShowTaxonConceptSerial
:key => :eu_listings
has_many :eu_decisions, :serializer => Species::EuDecisionSerializer

def include_distribution_references?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_standard_references?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_taxon_concept_references?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_cites_listing?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_eu_listing?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def quotas
Quota.from('api_cites_quotas_view trade_restrictions').
where("
Expand Down
20 changes: 20 additions & 0 deletions app/serializers/species/show_taxon_concept_serializer_cms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ class Species::ShowTaxonConceptSerializerCms < Species::ShowTaxonConceptSerializ
:key => :cms_listings
has_many :cms_instruments, :serializer => Species::CmsInstrumentsSerializer

def include_standard_references?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_taxon_concept_references?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_distribution_references?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def include_cms_listing?
return true unless @options[:trimmed]
@options[:trimmed] == 'false'
end

def cms_listing_changes
MCmsListingChange.from('cms_listing_changes_mview listing_changes_mview').
where(
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20220808124523_add_author_year_to_autocomplete_view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class AddAuthorYearToAutocompleteView < ActiveRecord::Migration
def up
execute "DROP VIEW IF EXISTS auto_complete_taxon_concepts_view"
execute "CREATE VIEW auto_complete_taxon_concepts_view AS #{view_sql('20220808123526', 'auto_complete_taxon_concepts_view')}"
execute File.read(File.expand_path('../../mviews/011_rebuild_auto_complete_taxon_concepts_mview.sql', __FILE__))
execute "SELECT * FROM rebuild_auto_complete_taxon_concepts_mview()"
end

def down
execute "DROP VIEW IF EXISTS auto_complete_taxon_concepts_view"
execute "CREATE VIEW auto_complete_taxon_concepts_view AS #{view_sql('20150318150923', 'auto_complete_taxon_concepts_view')}"
execute File.read(File.expand_path('../../mviews/011_rebuild_auto_complete_taxon_concepts_mview.sql', __FILE__))
execute "SELECT * FROM rebuild_auto_complete_taxon_concepts_mview()"
end
end
33 changes: 33 additions & 0 deletions db/mviews/011_rebuild_auto_complete_taxon_concepts_mview.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
CREATE OR REPLACE FUNCTION rebuild_auto_complete_taxon_concepts_mview() RETURNS void
LANGUAGE plpgsql
AS $$
BEGIN

DROP table IF EXISTS auto_complete_taxon_concepts_mview_tmp CASCADE;
RAISE INFO 'Creating auto complete taxon concepts materialized view (tmp)';
CREATE TABLE auto_complete_taxon_concepts_mview_tmp AS
SELECT * FROM auto_complete_taxon_concepts_view;

RAISE INFO 'Creating indexes on auto complete taxon concepts materialized view (tmp)';

--this one used for Species+ autocomplete (both main and higher taxa in downloads)
CREATE INDEX ON auto_complete_taxon_concepts_mview_tmp
USING BTREE(name_for_matching text_pattern_ops, taxonomy_is_cites_eu, type_of_match, show_in_species_plus_ac);
--this one used for Checklist autocomplete
CREATE INDEX ON auto_complete_taxon_concepts_mview_tmp
USING BTREE(name_for_matching text_pattern_ops, taxonomy_is_cites_eu, type_of_match, show_in_checklist_ac);
--this one used for Trade autocomplete
CREATE INDEX ON auto_complete_taxon_concepts_mview_tmp
USING BTREE(name_for_matching text_pattern_ops, taxonomy_is_cites_eu, type_of_match, show_in_trade_ac);
--this one used for Trade internal autocomplete
CREATE INDEX ON auto_complete_taxon_concepts_mview_tmp
USING BTREE(name_for_matching text_pattern_ops, taxonomy_is_cites_eu, type_of_match, show_in_trade_internal_ac);

RAISE INFO 'Swapping auto complete taxon concepts materialized view';
DROP table IF EXISTS auto_complete_taxon_concepts_mview CASCADE;
ALTER TABLE auto_complete_taxon_concepts_mview_tmp RENAME TO auto_complete_taxon_concepts_mview;

END;
$$;

COMMENT ON FUNCTION rebuild_taxon_concepts_mview() IS 'Procedure to rebuild taxon concepts materialized view in the database.';
Loading

0 comments on commit c5fe07c

Please sign in to comment.