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

Total Tag count on tag stats pages seems incorrect for tag "beach" #8244

Closed
jywarren opened this issue Aug 4, 2020 · 10 comments · Fixed by #8245
Closed

Total Tag count on tag stats pages seems incorrect for tag "beach" #8244

jywarren opened this issue Aug 4, 2020 · 10 comments · Fixed by #8245
Labels
help wanted requires help by anyone willing to contribute

Comments

@jywarren
Copy link
Member

jywarren commented Aug 4, 2020

Reporting in here from @ebarry and Jeanette, the graph at https://publiclab.org/tag/beach/stats seems correct, but below it the "Total Tag count" of 8 seems wrong, by their count.

Screen Shot 2020-07-27 at 10 56 45 AM

That code is driven from here:

<% if @tags.first.count.nil? %>
<i> There are no posts for this tag yet </i>
<% else %>
<b>Total Tag count : <%= @tags.first.count %></b>
<% end %>

Strange -- @tags.first.count would seem to be running Tag.where(name: params[:id]).first.count, which doesn't make sense to me.

Looking deeper, cc @cesswairimu as well...

@jywarren jywarren added the help wanted requires help by anyone willing to contribute label Aug 4, 2020
@jywarren
Copy link
Member Author

jywarren commented Aug 4, 2020

Aha - more sense here: it's not doing a database count, it's accessing an attribute named count on the Tag model:

irb(main):036:0> Tag.where(name: 'beach').first.count
=> 8
irb(main):037:0> Tag.where(name: 'beach').first
=> #<Tag tid: 15452, vid: 3, name: "beach", description: "", weight: 0, count: 8, parent: nil>

@jywarren
Copy link
Member Author

jywarren commented Aug 4, 2020

So, perhaps that's simply not getting updated. Let's see where else we count tag usage, and also where we update the attribute...

@jywarren
Copy link
Member Author

jywarren commented Aug 4, 2020

Looks like we need to be running this to maintain that attribute:

plots2/app/models/tag.rb

Lines 39 to 42 in d9e7f11

def run_count
self.count = NodeTag.where(tid: tid).count
save
end

We do that each time a tag is added:

tag.run_count # update count of tag usage

OK, so when run_count is run, we get 8 for beach

However, when we run this, we see there are only 4 notes (and no wikis) for beach:

Tag.find_nodes_by_type('beach', 'note').count

@jywarren
Copy link
Member Author

jywarren commented Aug 4, 2020

Aha - so 4 are attached to nodes that are not status = 1:

irb(main):053:0> NodeTag.joins(:node).where(tid: 15452).where('node.status = 1').count
=> 4
irb(main):055:0> NodeTag.joins(:node).where(tid: 15452).where('node.status != 1').count
=> 4

Great, there's our discrepancy!

@jywarren
Copy link
Member Author

jywarren commented Aug 4, 2020

OK wait we have to run run_count on all tags!!! https://stable.publiclab.org/tag/beach/stats

@jywarren jywarren reopened this Aug 4, 2020
@jywarren
Copy link
Member Author

jywarren commented Aug 4, 2020

So we'll need to run:

Tag.all.each do |tag|
  tag.run_count
end

@cesswairimu
Copy link
Collaborator

Great detective work 🎉

@jywarren
Copy link
Member Author

Running this on stable.publiclab.org now to test.

@ebarry
Copy link
Member

ebarry commented Sep 19, 2020

Exciting to see this detective work yield results!

@jywarren
Copy link
Member Author

jywarren commented Oct 6, 2020

Sorry, this was completed long ago and is live! Closing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted requires help by anyone willing to contribute
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants