Plots2: Empty pages on search results

Created on 22 Feb 2019  路  26Comments  路  Source: publiclab/plots2

When searching for something using tags, the results show more page numbers than necessary.
Most pages in the end are empty
plots

bug has-pull-request help wanted

Most helpful comment

Hi @gauravano
I managed to find the solution for this issue and I opened PR :)

All 26 comments

Hi @kaunair, I tried to reproduce the error but it seems to be alright to me.
screen shot 2019-02-22 at 7 45 03 pm

Can you please tell the steps to reproduce this issue?

Search for 'waste'
Go to tags section
Hit the pages at the end

It seems you haven't got any search result.
The problem arises when there are matches...the pages at the end are empty

Yup, you are right!

Thanks for reporting!! 馃憤

@namangupta01 Is this issue up for first timers? If yes, can you please point me to the instructions on how to recreate the issue.

@bhimak, yes this is a first timers issue and @kaunair has explained the steps above to reproduce it. Thanks

Hey @kaunair, thanks for reporting the issue.

@namangupta01 could you please edit the issue in this template - https://github.com/publiclab/plots2/blob/master/.github/first-timers-issue-template.md and also add the code snippets for solving this issue to make it a little easy for first-time contributor? Please feel free to add the label again after editing. Thanks!

@bhimak this issue will be edited soon, but you can have a look at other issues at https://code.publiclab.org/#r=all in the meantime. Also, if you can solve this issue without need of relevant file links or snippet, we would love to have a PR from you. Thank you!

Hi @gauravano
Is there a PR for this issue or it is still not solved?

@swiatek7 it is unresolved and available to claim.

@gauravano
Then I would like to claim it :)

Great!

@bhimak you can see more issues at code.publiclab.org/#r=all as I mentioned here https://github.com/publiclab/plots2/issues/4871#issuecomment-466649442. Also, you can collaborate with @swiatek7 for solving this one, if you like.

Thanks!

Also, I am doubtful if this one can be converted to FTO as a similar issue is open for /dashboard and it got pretty complex in Google Code-In and still unresolved.

Hi @gauravano
Is there any script, that could populate my dev DB?
I can't reproduce this bug on dev, because I don't have any entries that I can search through.

@swiatek7 there is a NPM package Faker that can be used to populate DB.

@gauravano
I thought about changing API EndPoint to publiclab.org, but I guess it won't work, since it is not SPA.

You can populate your DB using rake db:seed but as we have rake db:setup in our installation instructions - https://github.com/publiclab/plots2#standard-installation so your DB should contain data (if you followed the instructions). Have you checked the presence of data through console?

@gauravano sure I did, it provided me with users with I could log in, but it does not provide that many content with given tag in order to reproduce the bug.

@Yugandhartripathi thanks.
I can see, that npm package Faker is set up with some common data like users and their names,
Can you link it with RoR database schema, so that Faker generate some random data, lorem-ipsum like or so?

@swiatek7 sorry for late reply, Yes you can use it with RoR with faker gem. It can populate all kinds of data.

Quick update;
I managed to reproduce this bug and I am working on it currently.
I am planning to finish it till Friday.

Great!

Hi Everybody

I am sorry for late response, but I had emergencies to take care of and I am completely new to Ruby on Rails.

I was able to find root cause of this bug.
We select distinct values, but we count on not distinct.

SELECT  DISTINCT node.nid,node.title,node.path FROM "term_data" INNER JOIN "community_tags" ON "community_tags"."tid" = "term_data"."tid" INNER JOIN "community_tags" "node_tags_term_data_join" ON "node_tags_term_data_join"."tid" = "term_data"."tid" INNER JOIN "node" ON "node"."nid" = "node_tags_term_data_join"."nid" WHERE "term_data"."name" = ? AND (node.status = 1) LIMIT ? OFFSET ?  [["name", "one"], ["LIMIT", 11], ["OFFSET", 0]]

SELECT COUNT(*) FROM "term_data" INNER JOIN "community_tags" ON "community_tags"."tid" = "term_data"."tid" INNER JOIN "community_tags" "node_tags_term_data_join" ON "node_tags_term_data_join"."tid" = "term_data"."tid" INNER JOIN "node" ON "node"."nid" = "node_tags_term_data_join"."nid" WHERE "term_data"."name" = ? AND (node.status = 1)  [["name", "one"]]

Unfortunately no soultion I came up with seems to work.

First I found in the documentation that I could provide count argument to paginate function.

@tags = ExecuteSearch.new.by(:tags, @search_criteria).paginate(page: params[:page], per_page: 20)

But I get an error saying "unsupported parameters: :count"

Then after fetching tags for view I tried to overwrite total_pages property (attribute) with custom query:

  sterms = @search_criteria.query.split(' ')
  @tags.total_pages = Tag.where(name: sterms)
  .joins(:node_tag, :node)
  .where('node.status = 1')
  .count('DISTINCT node.nid')

But this gives me NoMethodError Exception: undefined method `total_pages='

Could you help me out here? :)

Also if there are other places where we select distinct values, then we will have there the same pagination issue.

Kind regards
Mateusz

Hi @gauravano
I managed to find the solution for this issue and I opened PR :)

Done here!!! Yay!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

first-timers[bot] picture first-timers[bot]  路  3Comments

first-timers[bot] picture first-timers[bot]  路  3Comments

keshavsethi picture keshavsethi  路  3Comments

jywarren picture jywarren  路  3Comments

bronwen9 picture bronwen9  路  3Comments