<commit_before>module Queries
  module Organisations

    def self.order_by_most_recent
      # users included for later query about icon size
      Organisation.includes(:users).order_by_most_recent
    end

    def self.search_by_keyword_and_category(parsed_params)
      organisations = order_by_most_recent.search_by_keyword(
        parsed_params.query_term
      )

      if parsed_params.what_who_how_ids.any?
        organisations.filter_by_categories(
          parsed_params.what_who_how_ids
        )
      else
        organisations
      end
    end

    FORMAT = '%Y-%m-%d %H:%M:%S.%N'

    def self.add_recently_updated_and_has_owner(organisations)
      if organisations.method(:select).arity == 0
        return add_recently_update_and_has_owner_to_enumerable(organisations)
      end
      one_year_ago = Time.current.advance(years: -1)
      recently_updated = "organisations.updated_at > '#{one_year_ago.strftime(FORMAT)}'"
      # recently_updated = "organisations.updated_at > #{one_year_ago.strftime}"
      has_owner = "organisations.id IN (SELECT users.organisation_id FROM users)"
      condition =
        "CASE WHEN #{recently_updated} AND #{has_owner} THEN TRUE ELSE FALSE END"
      organisations
        .select("organisations.*, (#{condition}) as recently_updated_and_has_owner")
    end

  private
    def self.add_recently_update_and_has_owner_to_enumerable(organisations)
      organisations.each do |o|
        o.instance_eval %{
            def recently_updated_and_has_owner
              !not_updated_recently? && !self.users.empty?
            end
         }
        return organisations
      end
    end
  end
end<commit_msg>Correct return statement after block, not in the middle of<commit_after>module Queries
  module Organisations

    def self.order_by_most_recent
      # users included for later query about icon size
      Organisation.includes(:users).order_by_most_recent
    end

    def self.search_by_keyword_and_category(parsed_params)
      organisations = order_by_most_recent.search_by_keyword(
        parsed_params.query_term
      )

      if parsed_params.what_who_how_ids.any?
        organisations.filter_by_categories(
          parsed_params.what_who_how_ids
        )
      else
        organisations
      end
    end

    FORMAT = '%Y-%m-%d %H:%M:%S.%N'

    def self.add_recently_updated_and_has_owner(organisations)
      if organisations.method(:select).arity == 0
        return add_recently_update_and_has_owner_to_enumerable(organisations)
      end
      one_year_ago = Time.current.advance(years: -1)
      recently_updated = "organisations.updated_at > '#{one_year_ago.strftime(FORMAT)}'"
      # recently_updated = "organisations.updated_at > #{one_year_ago.strftime}"
      has_owner = "organisations.id IN (SELECT users.organisation_id FROM users)"
      condition =
        "CASE WHEN #{recently_updated} AND #{has_owner} THEN TRUE ELSE FALSE END"
      organisations
        .select("organisations.*, (#{condition}) as recently_updated_and_has_owner")
    end

  private
    def self.add_recently_update_and_has_owner_to_enumerable(organisations)
      organisations.each do |o|
        o.instance_eval %{
            def recently_updated_and_has_owner
              !not_updated_recently? && !self.users.empty?
            end
         }
      end
      return organisations
    end
  end
end
{'fraction_non_alphanumeric': 0.07669529167900503, 'fraction_numerical': 0.0011844832691738228, 'mean_word_length': 3.0023696682464456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5200286', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1008, 'n_words': 190}