Class: ProgrammingLanguage

Inherits:
ApplicationRecord show all
Defined in:
app/models/programming_language.rb

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Class Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/programming_language.rb', line 14

def self.most_popular(limit = 25)
  sql = <<~SQL
    SELECT
      mcv
    FROM
      pg_stats
    CROSS JOIN LATERAL
      unnest(most_common_vals::text::int[]) mt(mcv)
    WHERE
      tablename = 'repository_languages' and attname='programming_language_id'
    LIMIT
      $1
  SQL
  ids = connection.exec_query(sql, 'SQL', [limit]).rows.flatten

  where(id: ids).order(:name)
end