Rails 5.2
, Postgresql
class School < ApplicationRecord
has_many :teacher_records
has_many :teachers, through: :teacher_records
end
TeacherRecord
model has #teacher_id
, #school_id
class TeacherRecord < ApplicationRecord
end
Teacher
model
class Teacher < ApplicationRecord
scope :search_by_full_name ->(query) { where("CONCAT_WS(' ', first_name, last_name) LIKE ?", "%#{query}%") }
end
Recently we imported 150000000
records of teachers from various sources.
Issue:
Search by full name takes 40seconds
to return the results.
Issue 2: Loading in table with pagination (10 records each page) takes 15 seconds for some small school which has few hundred records.