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

contributor count on tags page fixed #2055

Merged
merged 5 commits into from
Jan 23, 2018

Conversation

ViditChitkara
Copy link
Member

fixes #2042

Make sure these boxes are checked before your pull request is ready to be reviewed and merged. Thanks!

  • all tests pass -- rake test:all
  • code is in uniquely-named feature branch, and has been rebased on top of latest master (especially if you've been asked to make additional changes)
  • pull request is descriptively named with #number reference back to original issue

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/wiki/contributing-to-public-lab-software

We have a loose schedule of reviewing and pulling in changes every Tuesday and Friday, and publishing changes on Fridays. Please alert developers on plots-dev@googlegroups.com when your request is ready or if you need assistance.

Thanks!

@PublicLabBot
Copy link

PublicLabBot commented Jan 20, 2018

1 Message
📖 @ViditChitkara Thank you for your pull request! I’m here to help with some tips and recommendations. Please take a look at the list provided and help us review and accept your contribution! And don’t be discouraged if you see errors – we’re here to help.

Generated by 🚫 Danger

@ViditChitkara
Copy link
Member Author

@jywarren please see if this solves the problem!

@@ -321,7 +321,7 @@ def contributors
.references(:term_data, :node_revisions)
.where('term_data.name = ?', params[:id])
.order('node_revisions.timestamp DESC')
@users = @notes.collect(&:author).uniq
@users = DrupalUser.where(uid: Tag.contributors(@tagnames[0]))
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to use User.where(id: ... here instead, since we're trying to stop using DrupalUsers? Thank you! This otherwise looks fantastic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi, I guess we'd have to refactor the Tag.contributors method then, which currently gives array of uid (drupal_user id)!! Let's give it a try.

Copy link
Member Author

@ViditChitkara ViditChitkara Jan 22, 2018

Choose a reason for hiding this comment

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

@jywarren I guess we need to write a conversion function in user modal which fetches user_ids against drupal_user_ids. Then we could replace the DrupalUser with User in L324. Do you think this is the correct way, however it doesn't completely rules out DrupalUser.
The function would look something like (Would go in User Model):-

def self.user_ids(drupal_user_ids)
  user_ids=[]
  drupal_users = DrupalUser.include(:user).where(uid: drupal_user_ids)
  drupal_users.each do |du|
    user_ids<<du.user.id
  end
end

This would greatly increase the overload time since a separate query is required to fetch a user from drupal_user. Do you think we should do this???

Copy link
Member

Choose a reason for hiding this comment

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

So, we've synced User.id and DrupalUser.uid and you can treat one like the other -- we did a big database migration a while back to ensure this. Does that help?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh cool!! That would just need a line change and then it would be good to go!!
Yes, that helped!

@@ -52,8 +52,9 @@ def belongs_to(current_user, nid)
node_tag && node_tag.uid == current_user.uid || node_tag.node.uid == current_user.uid
end

def self.contributor_count(tagname)
def self.contributors(tagname)
Copy link
Member

Choose a reason for hiding this comment

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

Love this!!! 👍 👍

@jywarren
Copy link
Member

I think this looks perfect. Did you want to add a simple unit test for Tag.contributors?

@ViditChitkara
Copy link
Member Author

Sure, I'll do!

@ViditChitkara
Copy link
Member Author

Done with the tests!

@@ -62,6 +63,11 @@ def self.contributor_count(tagname)
uids+=n.revision.collect(&:uid)
end
uids = uids.uniq
uids
Copy link
Member

Choose a reason for hiding this comment

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

Ah, so, do you think we should return an ActiveRecord collection here, instead of just uids? Like, replace this line with User.find uids instead -- and then the line above (https://github.com/publiclab/plots2/pull/2055/files#diff-a8eb2425ebeb0814d010864bb014e815R326) would be simpler -- make sense?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, makes sense, will do!!

Copy link
Member Author

Choose a reason for hiding this comment

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

@jywarren done with the suggested changes!

@@ -68,7 +68,7 @@

<% end %>

<% if @notes.nil? || @notes.length == 0 %>
<% if @users.nil? || @users.length == 0 %>
Copy link
Member Author

Choose a reason for hiding this comment

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

Found some unexpected behaviour when @notes.length was 0 but @users still existed hence modified the condition a bit!!

@jywarren
Copy link
Member

Super, is this ready to go, then? Thanks!

@ViditChitkara
Copy link
Member Author

ViditChitkara commented Jan 23, 2018 via email

@jywarren jywarren merged commit ceb7d05 into publiclab:master Jan 23, 2018
@jywarren
Copy link
Member

Awesome!

SrinandanPai pushed a commit to SrinandanPai/plots2 that referenced this pull request May 5, 2019
* contributor count on tags page fixed

fixes publiclab#2042

* minor tweaks

* changes

* added unit tests for Tag.contributors

* minor tweaks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

List wiki revision authors as contributors on /contributors/tagname pages
3 participants