<commit_before>module Sapi
  module StoredProcedures

    def self.rebuild
      [
        :taxonomy,
        :cites_accepted_flags,
        :listing_changes_mview,
        :cites_listing,
        :eu_listing,
        :cms_listing,
        :taxon_concepts_mview,
        :cites_species_listing_mview,
        :eu_species_listing_mview,
        :cms_species_listing_mview,
        :valid_species_name_appendix_year_mview,
        :touch_taxon_concepts
      ].each{ |p|
        puts "Procedure: #{p}"
        ActiveRecord::Base.connection.execute("SELECT * FROM rebuild_#{p}()")
      }

      changed_cnt = TaxonConcept.where('touched_at IS NOT NULL AND touched_at > updated_at').count

      if changed_cnt > 0
        # increment cache iterators if anything changed
        Species::Search.increment_cache_iterator
        Species::TaxonConceptPrefixMatcher.increment_cache_iterator
        Checklist::Checklist.increment_cache_iterator

        TaxonConcept.update_all(
          'updated_at = touched_at',
          'touched_at IS NOT NULL AND touched_at > updated_at'
        )
      end
    end

  end
end
<commit_msg>add rebuild procedures per designation<commit_after>module Sapi
  module StoredProcedures

    def self.rebuild
      [
        :taxonomy,
        :cites_accepted_flags,
        :listing_changes_mview,
        :cites_listing,
        :eu_listing,
        :cms_listing,
        :taxon_concepts_mview,
        :cites_species_listing_mview,
        :eu_species_listing_mview,
        :cms_species_listing_mview,
        :valid_species_name_appendix_year_mview,
        :touch_taxon_concepts
      ].each{ |p|
        puts "Procedure: #{p}"
        ActiveRecord::Base.connection.execute("SELECT * FROM rebuild_#{p}()")
      }

      changed_cnt = TaxonConcept.where('touched_at IS NOT NULL AND touched_at > updated_at').count

      if changed_cnt > 0
        # increment cache iterators if anything changed
        Species::Search.increment_cache_iterator
        Species::TaxonConceptPrefixMatcher.increment_cache_iterator
        Checklist::Checklist.increment_cache_iterator

        TaxonConcept.update_all(
          'updated_at = touched_at',
          'touched_at IS NOT NULL AND touched_at > updated_at'
        )
      end
    end

    def self.rebuild_cms_taxonomy_and_listings
      run_procedures [
        :taxonomy,
        :cms_taxon_concepts_and_ancestors_mview,
        :cms_listing_changes_mview,
        :cms_listing,
        :taxon_concepts_mview,
        :cms_species_listing_mview,
        :touch_taxon_concepts
      ]
    end

    def self.rebuild_cites_taxonomy_and_listings
      run_procedures [
        :taxonomy,
        :cites_accepted_flags,
        :cites_eu_taxon_concepts_and_ancestors_mview,
        :cites_listing_changes_mview,
        :cites_listing,
        :taxon_concepts_mview,
        :cites_species_listing_mview,
        :touch_taxon_concepts
      ]
    end

    def self.rebuild_eu_taxonomy_and_listings
      run_procedures [
        :taxonomy,
        :cites_eu_taxon_concepts_and_ancestors_mview,
        :eu_listing_changes_mview,
        :eu_listing,
        :taxon_concepts_mview,
        :eu_species_listing_mview,
        :touch_taxon_concepts
      ]
    end

    def self.run_procedures(procedures)
      procedures.each{ |p|
        puts "Procedure: #{p}"
        ActiveRecord::Base.connection.execute("SELECT * FROM rebuild_#{p}()")
      }
    end
  end
end

{'fraction_non_alphanumeric': 0.07093023255813953, 'fraction_numerical': 0.0005813953488372093, 'mean_word_length': 2.562111801242236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3208057', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1110, 'n_words': 169}