diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index a32f49912..e03fff694 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -11,16 +11,21 @@ def rankings; end private + def only_device? + request.env['HTTP_USER_AGENT']&.match?(/(iPhone|BlackBerry|Android)/) + end + def query_or_cache_exist - params[:query].blank? && Rails.cache.exist?('people_index_page') && Rails.cache.exist?('people_index_page_device') + key = only_device? ? 'people_index_page_device' : 'people_index_page' + params[:query].blank? && Rails.cache.exist?(key) end def find_index_people @claimed_people = Person.find_claimed(params[:query], 'relevance') - .preload(account: :markup) .paginate(page: 1, per_page: 3) - @unclaimed_people = unclaimed_people(params[:query], 'relevance', 3) - @unclaimed_people_count = Person::Count.unclaimed_by(params[:query], 'relevance') + @unclaimed_people = unclaimed_people(params[:query], 'relevance', 4) + @more_unclaimed = @unclaimed_people.length > 3 + @unclaimed_people = @unclaimed_people.first(3) end def preload_data diff --git a/app/controllers/unclaimed_controller.rb b/app/controllers/unclaimed_controller.rb index f84b0b9d0..d0256be8e 100644 --- a/app/controllers/unclaimed_controller.rb +++ b/app/controllers/unclaimed_controller.rb @@ -38,15 +38,17 @@ def find_emails(email_ids) end def unclaimed_people(query, find_by, per_page = 10) - name_ids = Person.joins(project: :best_analysis).unclaimed_people(q: query, - find_by: find_by).limit(per_page).pluck(:name_id) + name_ids = Person.unclaimed_people(q: query, find_by: find_by) + .joins(:project) + .where.not(projects: { best_analysis_id: nil }) + .limit(per_page).pluck(:name_id) unclaimed_people_with_limit(name_ids) end # NOTE: Since this approach avoids the *includes*, it takes 3x DB time. However this prevents memory hog. def unclaimed_people_with_limit(unclaimed_name_ids) unclaimed_name_ids.map do |name_id| - [name_id, Person.include_relations_and_order_by_kudo_position_and_name(name_id).limit(UNCLAIMED_TILE_LIMIT)] + [name_id, Person.include_relations_and_order_by_kudo_position_and_name(name_id).limit(UNCLAIMED_TILE_LIMIT).to_a] end end end diff --git a/app/models/account.rb b/app/models/account.rb index 9a24ee4eb..96c89ec21 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -52,7 +52,11 @@ def edit_count end def best_account_analysis - AccountAnalysis.find_by(id: best_vita_id, account_id: id) || NilAccountAnalysis.new + if association(:best_account_analysis).loaded? + super || NilAccountAnalysis.new + else + AccountAnalysis.find_by(id: best_vita_id, account_id: id) || NilAccountAnalysis.new + end end def email_topics? diff --git a/app/models/person.rb b/app/models/person.rb index 3332aceb4..e6a5d320e 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -49,7 +49,7 @@ def find_claimed(query, sort_by) sort_by = sort_by.eql?('kudo_position') ? 'sort_by_kudo_position' : nil tsearch(query, sort_by) .includes(:account) - .preload(account: :markup) + .preload(account: [:markup, :projects, { best_account_analysis: :name_fact }]) .where.not(account_id: nil) .references(:all) end @@ -70,8 +70,8 @@ def rebuild_by_project_id(project_id) end def include_relations_and_order_by_kudo_position_and_name(name_id) - joins(project: :best_analysis).includes({ project: [{ best_analysis: :main_language }, :logo] }, :name, - name_fact: :primary_language) + joins(project: :best_analysis).preload({ project: [{ best_analysis: :main_language }, :logo] }, :name, + name_fact: :primary_language) .where(name_id: name_id) .order(Arel.sql('COALESCE(kudo_position, 999999999), lower(effective_name)')) end diff --git a/app/views/people/_claimed_person.html.haml b/app/views/people/_claimed_person.html.haml index c3d6aed8c..ea8641f3e 100644 --- a/app/views/people/_claimed_person.html.haml +++ b/app/views/people/_claimed_person.html.haml @@ -16,8 +16,7 @@ .pull-left.account_details %h3 %a.margin_top_20{ href: account_path(account), title: account.name }= truncate(account.name, length: 18) - - markup_raw = account.markup ? account.markup.raw : '' - %p.small.word_break_all= truncate(Markup.create(raw: markup_raw).first_line, length: 75) + %p.small.word_break_all= truncate(account.markup&.first_line.to_s, length: 75) .small.member_info - if account.projects.any? %p diff --git a/app/views/people/_people.html.haml b/app/views/people/_people.html.haml index 7a64bdde6..60d7759dc 100644 --- a/app/views/people/_people.html.haml +++ b/app/views/people/_people.html.haml @@ -9,6 +9,6 @@ %h3.margin_bottom_15= t('.unclaimed_committer_ids') - @unclaimed_people.each do |_, people| = render partial: 'unclaimed_person', locals: { people: people } - - if @unclaimed_people_count > 3 + - if @more_unclaimed %p %a.btn.btn-mini.btn-primary#more_unclaimed{ href: committers_path(query: params[:query]) }= t('.more_commiters') diff --git a/db/migrate/20260603065929_add_index_to_people_name_id_kudo_position.rb b/db/migrate/20260603065929_add_index_to_people_name_id_kudo_position.rb new file mode 100644 index 000000000..d5efa37d3 --- /dev/null +++ b/db/migrate/20260603065929_add_index_to_people_name_id_kudo_position.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class AddIndexToPeopleNameIdKudoPosition < ActiveRecord::Migration[6.1] + disable_ddl_transaction! + + def change + add_index :people, %i[name_id kudo_position], + where: 'name_id IS NOT NULL', + name: 'index_people_name_id_kudo_position', + algorithm: :concurrently + end +end diff --git a/db/structure.sql b/db/structure.sql index b656add6b..21e19176e 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -20539,6 +20539,13 @@ CREATE INDEX index_people_gin ON oh.people USING gin (vector); CREATE INDEX index_people_name_id ON oh.people USING btree (name_id) WHERE (name_id IS NOT NULL); +-- +-- Name: index_people_name_id_kudo_position; Type: INDEX; Schema: oh; Owner: - +-- + +CREATE INDEX index_people_name_id_kudo_position ON oh.people USING btree (name_id, kudo_position) WHERE (name_id IS NOT NULL); + + -- -- Name: index_people_on_account_id; Type: INDEX; Schema: oh; Owner: - -- @@ -28227,3 +28234,5 @@ INSERT INTO oh.schema_migrations (version) VALUES ('98'); INSERT INTO oh.schema_migrations (version) VALUES ('99'); + +INSERT INTO oh.schema_migrations (version) VALUES ('20260603065929');