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

topic card count fixes for #7965 #8249

Merged
merged 2 commits into from
Aug 4, 2020
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
10 changes: 4 additions & 6 deletions app/models/node_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ class NodeTag < ApplicationRecord
has_many :tag_selections, foreign_key: 'tid'
accepts_nested_attributes_for :tag

after_create :increment_count
after_create :update_count
Copy link
Member Author

Choose a reason for hiding this comment

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

Adding better updaters for tag counting

after_destroy :update_count

def increment_count
tag = self.tag
tag.count = 0 if tag.count.nil?
tag.count += 1
tag.save
def update_count
tag.run_count # update count of tag usage
end

def user
Expand Down
8 changes: 0 additions & 8 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,6 @@ def self.find_nodes_by_type(tagnames, type = 'note', limit = 10)
.order(order)
end

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

# just like find_nodes_by_type, but searches wiki pages, places, and tools
def self.find_pages(tagnames, limit = 10)
find_nodes_by_type(tagnames, %w(page place tool), limit)
Expand Down
2 changes: 1 addition & 1 deletion app/views/tag/_topicCard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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>
<a style="padding-top:15px;text-decoration:underline;color:#808080;display:inline-block;" href="/tag/<%= tag.name %>"><%= Tag.count %> <%= translation('tag.index.posts') %> &raquo;</a>
Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, it should've been tag.count not Tag.count -- fixing in follow-up!!!

<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
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ en:
number_of_subscriptions: "# of people"
subscriptions: "Your subscriptions"
sort_by: "Sort By"
more_posts: "more posts"
posts: "posts"
follow: "Follow"
unfollow: "Unfollow"
notes:
Expand Down