Skip to content

Commit

Permalink
Fixes #11203: Refined Information hierarchy on profile page (#11204)
Browse files Browse the repository at this point in the history
* Fixes #11203: Refined Information hierarchy on profile page

* Used conditional assignment

* Used  as default value for author_id

* Used single argument in where query

* Added space in curly brackets (codeclimate issue)
  • Loading branch information
KarishmaVanwari committed Jul 7, 2022
1 parent 0d2f63b commit a8688d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 7 additions & 5 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ def self.find_top_nodes_by_type(tagname:, type: 'wiki', limit: 10)
end

# finds recent nodes - should drop "limit" and allow use of chainable .limit()
def self.find_nodes_by_type(tagnames, type = 'note', limit = 10)
nodes = Node.where(status: 1, type: type)
.includes(:tag)
.references(:term_data)
.where('term_data.name IN (?)', tagnames)
def self.find_nodes_by_type(tagnames, type = 'note', limit = 10, author_id = nil)
query = { status: 1, type: type }
query['uid'] = author_id unless author_id.blank?
nodes = Node.where(query)
.includes(:tag)
.references(:term_data)
.where('term_data.name IN (?)', tagnames)
# .select(%i[node.nid node.status node.type community_tags.nid community_tags.tid term_data.name term_data.tid])
# above select could be added later for further optimization
order = 'node_revisions.timestamp DESC'
Expand Down
3 changes: 1 addition & 2 deletions app/views/tag/_profileCard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<p class="posted-by-links"><a href="/tag/<%= tag.name %>"><%= pluralize(Tag.follower_count(tag.name), 'person') %> discussing</a></p>
</div>
<div class="card-body">
<% Tag.find_nodes_by_type(tag.name, type = 'note', limit = 3).each do |node| %>
<% Tag.find_nodes_by_type(tag.name, type = 'note', limit = 3, author_id = @profile_user.id).each do |node| %>
<div class="posted-by-links">
<% if node.main_image %>
<img class="rounded-circle" id="profile-photo" style="width:20px; height:20px; margin-right:8px; display: inline-block;" src="<%= node.main_image.path(:default) %>" />
Expand All @@ -17,7 +17,6 @@
<div class="circle"></div>
<% end %>
<a class="post-title" <% if @widget %>target="_blank"<% end %> href="<%= node.path %>"><%= (node.type == 'note') ? node.title : node.latest.title %></a>
by <a href="/profile/<%= node.author.name %>" class="text-decoration-none">@<%= node.author.name %></a>
</div>
<% end %>
</div>
Expand Down

0 comments on commit a8688d5

Please sign in to comment.