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

Results are not sorted according to views #3531

Closed
radheyshyamjangid opened this issue Sep 28, 2018 · 24 comments · Fixed by #5307
Closed

Results are not sorted according to views #3531

radheyshyamjangid opened this issue Sep 28, 2018 · 24 comments · Fixed by #5307
Labels
bug the issue is regarding one of our programs which faces problems when a certain task is executed

Comments

@radheyshyamjangid
Copy link

Please describe the problem (or idea)

results are not sorted according to views in wikis

What happened just before the problem occurred? Or what problem could this idea solve?
image

What did you expect to see that you didn't?

the results should be sorted according to page views.

Please show us where to look

https://publiclab.org/search/wikis/science+community?order=views

What's your PublicLab.org username?

jradheyshyam96

This can help us diagnose the issue:

Browser, version, and operating system

Windows 10 chrome

Many bugs are related to these -- please help us track it down and reproduce what you're seeing!


Thank you!

Your help makes Public Lab better! We deeply appreciate your helping refine and improve this site.

To learn how to write really great issues, which increases the chances they'll be resolved, see:

https://publiclab.org/wiki/developers#Contributing+for+non-coders

@welcome
Copy link

welcome bot commented Sep 28, 2018

Thanks for opening your first issue here! Please follow the issue template to help us help you 👍🎉😄
If you have screenshots to share demonstrating the issue, that's really helpful! 📸

@avsingh999
Copy link
Member

@radheyshyamjangid great catch

@igniteeng000
Copy link
Member

@igniteeng000
Copy link
Member

result are not sorted according to page views also.

@avsingh999
Copy link
Member

@igniteeng000 I think he saying same as

@igniteeng000
Copy link
Member

@avsingh999 @radheyshyamjangid please look at the links they both are different.

@radheyshyamjangid
Copy link
Author

@igniteeng000 yup u are right, it is not working as should need to be. Contents are not sorting after clicking.

@radheyshyamjangid
Copy link
Author

@avsingh999 nope it is different

@SidharthBansal
Copy link
Member

great catch @radheyshyamjangid.
May I know who is working on this out of @igniteeng000 @radheyshyamjangid @avsingh999 ??

@SidharthBansal
Copy link
Member

#2002 might help.
I resolved a similar bug few months back

@igniteeng000
Copy link
Member

I am not working on this. @SidharthBansal Please label this issue with appropriate tags.

@SidharthBansal SidharthBansal added the bug the issue is regarding one of our programs which faces problems when a certain task is executed label Sep 30, 2018
@14Richa
Copy link

14Richa commented Sep 30, 2018

@SidharthBansal Can you assign this bug to me? I would like to try my hands on this!

@SidharthBansal
Copy link
Member

Go ahead. No one has claimed to solve this issue before you. So you can solve this.

@SidharthBansal
Copy link
Member

Hi, just checking if you've gotten stuck on this at all, or if I could help in any way? Thanks!

@14Richa
Copy link

14Richa commented Oct 3, 2018 via email

@14Richa
Copy link

14Richa commented Oct 9, 2018

Hey Sidharth,
In my local session I think this works fine. Can you help me find what am I missing or is this issue resolved? Attached gif:
Thanks

sortbyviews

@SidharthBansal
Copy link
Member

SidharthBansal commented Oct 10, 2018 via email

@alonpeer
Copy link
Contributor

I believe this is happening because the actual number of views is the sum of node.views and node.legacy_views, while the ORDER BY part of the queries only takes node.views into account. I cannot verify my guess, since I don't have access to the production DB, and I'm only partially familiar with the system.

I see two possible fixes:

  1. Replace .order('views DESC') with `.order('(views + legacy_views) DESC').
    Pro: operation in the DB layer instead of app.
    Con: this seems to be an operation that is considered deprecated in future Rails versions:
DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) 
called with non-attribute argument(s): "(node.views + node.legacy_views) DESC". Non-attribute 
arguments will be disallowed in Rails 6.0. This method should not be called with user-provided values, 
such as request parameters or model attributes. Known-safe values can be passed by wrapping them 
in Arel.sql().
  1. Replace .order('views DESC') with .sort_by(&:totalviews).reverse.
    Pro: it works and uses the same views count as the one used for display.
    Con: it shifts the sorting to the app layer, which means the app must pull all nodes in order to sort them in memory. I don't know how big the set of nodes might be, but it should be fine if it's just a few hundreds.

  2. Make a DB migration where legacy_views values are added to the views column, then deprecating that column completely.
    Pro: it simplifies the app and helps avoid confusion. Also, solves the problems with the first two solutions.
    Con: might involve much more work.

In order to help us make a choice here, it would be good to get some data about what's the largest number of wiki pages per tag that currently exists in the DB.

My personal opinion is that the third option is the best one, and I'm happy to help with planning and execution.

@jywarren
Copy link
Member

jywarren commented Mar 18, 2019 via email

@alonpeer
Copy link
Contributor

@jywarren great!
What would be the best way of verifying that views does not get recalculated?
And what would be the best way for me to pair with someone on this?

@jywarren
Copy link
Member

jywarren commented Mar 18, 2019 via email

@alonpeer
Copy link
Contributor

Ahh, this ticket from 2017 seems to be very much related: #1196

@alonpeer
Copy link
Contributor

The column node.views is being used as the counter_cache for the impressions counter gem "impressionist". This means that it always gets re-evaluated.
When there's a new impression on a node page, the gem will INSERT INTO impressions a new row, and will also UPDATE node SET views = views + 1 WHERE nid = ?.
I think what we can do, in order to deprecated legacy_views, is to run a migration with UPDATE node SET views = views + legacy_views, and then just make use of node.views anywhere we need that data (for display or sorting).

@alonpeer
Copy link
Contributor

Related PR: #5248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug the issue is regarding one of our programs which faces problems when a certain task is executed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants