Skip to content

Commit

Permalink
remove the main_or_tag method altogether and remove an addional query…
Browse files Browse the repository at this point in the history
… for finding the profile in the profile partial,

that means it makes no sense to use a struct in the search because in order to fetch the image of the profile we always needed to fetch the profile anyway and when you already have it like in the other index pages you are always loading the profile twice
  • Loading branch information
Tyranja committed Jul 25, 2024
1 parent cf994ea commit adc4c56
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def profile_params
end

def search_with_search_params
@profiles = matching_profiles.map(&:profile_card_details)
@profiles = matching_profiles
@pagy, @records = pagy_array(@profiles)
# search results aggregated according to certain attributes to display as filters
aggs = ProfileGrouper.new(params[:locale], @profiles.map { |profile| profile[:id] }).agg_hash
Expand Down
1 change: 0 additions & 1 deletion app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Category < ApplicationRecord

def self.sorted_categories
Category.all.includes(:translations).order(:position)

end

def short_name
Expand Down
30 changes: 0 additions & 30 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,6 @@ def self.typeahead(term, region: nil)
suggestions.map { |s| s.downcase }.uniq
end

Struct.new(
'ProfileCardDetails',
:id,
:fullname,
:iso_languages,
:city,
:willing_to_travel,
:nonprofit,
:main_topic_or_first_topic,
keyword_init: true
)

def profile_card_details
Struct::ProfileCardDetails.new(
id: id,
fullname: fullname,
iso_languages: iso_languages,
city: city,
willing_to_travel: willing_to_travel,
nonprofit: nonprofit,
main_topic_or_first_topic: main_topic_or_first_topic,
)
end

def fullname
"#{firstname} #{lastname}".strip
end
Expand All @@ -150,12 +126,6 @@ def name_or_email
fullname.present? ? fullname : email
end

def main_topic_or_first_topic
return nil unless main_topic

main_topic
end

# Try building a slug based on the following fields in
# increasing order of specificity.
def slug_candidate
Expand Down
2 changes: 1 addition & 1 deletion app/views/profiles/_profile.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</div>
<div class="profile-subtitle">
<p>
<%= profile.main_topic_or_first_topic.truncate(60) if profile.main_topic_or_first_topic %>
<%= profile.main_topic.truncate(60) if profile.main_topic %>
</p>
<div
class="profile-tooltip"
Expand Down
4 changes: 2 additions & 2 deletions app/views/profiles/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
</p>
<% end %>
<!-- main topic -->
<% if @profile.main_topic_or_first_topic %>
<% if @profile.main_topic %>
<p class="">
<span class="font-weight-bold">
<%= t(:main_topic, scope: 'profiles.show') %>
</span>
<%= @profile.main_topic_or_first_topic %>
<%= @profile.main_topic %>
</p>
<% end %>
<!-- twitter -->
Expand Down

0 comments on commit adc4c56

Please sign in to comment.