Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions app/controllers/unclaimed_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment thread
bd-vaibhav marked this conversation as resolved.
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
6 changes: 5 additions & 1 deletion app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
bd-vaibhav marked this conversation as resolved.
end
end

def email_topics?
Expand Down
6 changes: 3 additions & 3 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions app/views/people/_claimed_person.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/people/_people.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Original file line number Diff line number Diff line change
@@ -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
Comment thread
bd-vaibhav marked this conversation as resolved.
9 changes: 9 additions & 0 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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: -
--
Expand Down Expand Up @@ -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');
Loading