Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct tag count #8048

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 4 additions & 4 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ def self.find_nodes_by_type(tagnames, type = 'note', limit = 10)
end

def self.counter(tagname)
Node.where(type: %w(note page))
.where('term_data.name = ?', tagname)
.includes(:node_tag, :tag)
.references(:term_data)
Node.where(status: 1, type: %w(note page))
.includes(:revision, :tag)
.references(:term_data, :node_revisions)
.where('term_data.name = ? OR term_data.parent = ?', tagname, tagname)
.count
end

Expand Down
4 changes: 3 additions & 1 deletion app/views/tag/_topicCard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
</div>
<div class="card-body" style="padding:0.8em;">
<div class="node-list">
<% count = 0 %>
<% Tag.find_nodes_by_type(tag.name, type = 'note', limit = 3).where.not(nid: shown_nids).each do |node| %>
<% shown_nids << node.id %>
<% count = count + 1 %>
<div class="node-body">
<% if node.main_image %>
<img class="rounded-circle pull-left" id="profile-photo" style="width:20px; height:20px; margin-right:8px; display: inline-block;" src="<%= node.main_image.path(:default) %>" />
Expand All @@ -32,7 +34,7 @@
</div>

<div class="card-footer" style="background-color: inherit; border:none;">
<a style="padding-top:15px;text-decoration:underline;color:#808080;display:inline-block;" href="/tag/<%= tag.name %>"><%= Tag.counter(tag.name)-shown_nids.count - Tag.find_nodes_by_type(tag.name, type = 'note', limit = 3).where.not(nid: shown_nids).count %> <%= translation('tag.index.more_posts') %> &raquo;</a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha - so, i think here we actually do need to keep -shown_nids.count because that takes the total, but deducts the currently displayed posts because the link says X more posts -- does that make sense? I think your fix should still work because it resolves the spam filtering on line 119 of the controller.

Can you re-add the offset for the already-displayed posts? Thank you!!!

Copy link
Contributor Author

@urvashigupta7 urvashigupta7 Jun 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a doubt @jywarren 😅, for example, we have 2 posts with tag one and 1 post with tag one and two both,
and all the 3 posts gets displayed in the topic card for tag one. So, topic card of two should show 0 more posts since the post which had both tags(one and two) is displayed already in topic card of tag-one. I guess this is the thing we want here, right ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha - yes. So we could maybe use this syntax --

[Tag.counter(tag.name)-shown_nids.count - Tag.find_nodes_by_type(tag.name, type = 'note', limit = 3).where.not(nid: shown_nids).count, 0].max

?

<a style="padding-top:15px;text-decoration:underline;color:#808080;display:inline-block;" href="/tag/<%= tag.name %>"><%= [Tag.counter(tag.name) - shown_nids.count - Tag.find_nodes_by_type(tag.name, type = 'note', limit = 3).where.not(nid: shown_nids).count, 0].max %> <%= translation('tag.index.more_posts') %> &raquo;</a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<a style="padding-top:15px;text-decoration:underline;color:#808080;display:inline-block;" href="/tag/<%= tag.name %>"><%= [Tag.counter(tag.name) - shown_nids.count - Tag.find_nodes_by_type(tag.name, type = 'note', limit = 3).where.not(nid: shown_nids).count, 0].max %> <%= translation('tag.index.more_posts') %> &raquo;</a>
<a style="padding-top:15px;text-decoration:underline;color:#808080;display:inline-block;" href="/tag/<%= tag.name %>"><%= [Tag.counter(tag.name) - Tag.find_nodes_by_type(tag.name, type = 'note').where(nid: shown_nids).count, 0].max %> <%= translation('tag.index.more_posts') %> &raquo;</a>

<div id="follow-unfollow-column-<%=tag.tid%>" style="float:right;margin:10px 0 10px 10px;">
<% if current_user %>
<% if !current_user.following(tag.name) %>
Expand Down