mirror of
https://github.com/chenasraf/snpr.git
synced 2026-05-18 01:39:01 +00:00
* Breaks up Zipfulldata worker into service classes * Fixes N+1 queries for phenotype and picture phenotype CSVs * moving phenotype CSV generation into database for performance * Fixes unintentional deletion of unrelated files * Reduces the time it takes to assemble the zip file from about 10 to about 5 hours, with the bottle-neck being zipping the genotype files
41 lines
900 B
Ruby
41 lines
900 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Phenotype < ApplicationRecord
|
|
include PgSearchCommon
|
|
|
|
has_many :user_phenotypes, dependent: :destroy
|
|
has_many :phenotype_comments, dependent: :destroy
|
|
has_and_belongs_to_many :phenotype_sets
|
|
|
|
validates :characteristic, presence: true
|
|
|
|
accepts_nested_attributes_for :user_phenotypes
|
|
|
|
pg_search_common_scope against: :characteristic
|
|
|
|
def number_of_users
|
|
user_phenotypes.count
|
|
end
|
|
|
|
def known_phenotypes
|
|
user_phenotypes
|
|
.pluck(:variation)
|
|
.map(&:capitalize)
|
|
.uniq
|
|
end
|
|
|
|
def self.with_number_of_users
|
|
from(
|
|
select('phenotypes.*, count(user_phenotypes.*) as number_of_users')
|
|
.joins('LEFT JOIN user_phenotypes ON user_phenotypes.phenotype_id = phenotypes.id')
|
|
.group(1)
|
|
.as('phenotypes')
|
|
)
|
|
end
|
|
|
|
def number_of_users
|
|
self[:number_of_users] || user_phenotypes.count
|
|
end
|
|
end
|
|
|