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

Iagirre budget pagination bug #2131

Merged

Conversation

iagirre
Copy link

@iagirre iagirre commented Nov 15, 2017

Where

What

There was a bug when a user navigates from one investment page to another. This bug repeated the investmentes between pages, and there where other investments that didn't appear.
e.g. Page 1 contains 4, 7, 2, 8, 3; Page 2 contains 7, 4, 1 -> 5 and 6 are missing, because 4 and 7 are repeated.

How

I followed this Stackoverflow answer to make a semi-random order (it's not a real random selection, but it makes what we want for this case), because I detected that using random() (event if we use PostgreSQL setseed to set a seed) is not maintaining the order from the variable we get on controller and the one used in the view (the variable in the each loop. Something that may be involved). I think that this is the problem with repeating objects between pages.

Screenshots

Nothing to show.

Test

  • I added some test to check that the objects are not been repeated through pages
  • I added another test (taken from Madrid's fork) to check that different users, each one in their browser, get different investment order BUT each one is consistent when they navigate forward and backward through pages.

Deployment

Nothing to apply.

Warnings

Nothing to apply

As a side note

I changed the test from Madrid's fork slighly to check the order when the user navigates through pages, instead of visiting the budget_investments_path again. As I understood, the order should be maintained when users change the page, not when they revisit it (talking about random order).

@bertocq bertocq added this to the v0.11 milestone Nov 21, 2017
@voodoorai2000
Copy link
Member

Awesome @iagirre! 👌

@voodoorai2000 voodoorai2000 merged commit 778ddbe into consuldemocracy:master Nov 27, 2017
@iagirre iagirre deleted the iagirre-budget-pagination-bug branch January 16, 2018 07:24
voodoorai2000 added a commit to AyuntamientoMadrid/consul that referenced this pull request Mar 1, 2018
We are trying out a modulus function to return investments in random
order consuldemocracy#2131

However we ran into the gotcha of having a seed value too big for the
modulus function to work as expected

If the seed is bigger than the investment id, the records are returned
ordered by id

By dividing the seed by a big number, this problem seems to get fixed
voodoorai2000 added a commit to AyuntamientoMadrid/consul that referenced this pull request Mar 1, 2018
This is a defensive test, just in case we decide to go back to using
`setseed` instead of the `modulus`[1] approach to display investments
in random order

The reason for this test is that `setseed` only ~works in the next
`select` statement. And as when loading a user’s votes for investments
we do a second `select` it does not work as expected 😌

To solve this… we could call `set_random_seed` before loading a user’s
votes for an investment[2]

[1] consuldemocracy#2131
[2]
https://github.com/AyuntamientoMadrid/consul/blob/master/app/controllers
/budgets/investments_controller.rb#L37
voodoorai2000 added a commit that referenced this pull request Apr 5, 2018
We are trying out a modulus function to return investments in random
order #2131

However we ran into the gotcha of having a seed value too big for the
modulus function to work as expected

If the seed is bigger than the investment id, the records are returned
ordered by id

By dividing the seed by a big number, this problem seems to get fixed
voodoorai2000 added a commit that referenced this pull request Apr 5, 2018
This is a defensive test, just in case we decide to go back to using
`setseed` instead of the `modulus`[1] approach to display investments
in random order

The reason for this test is that `setseed` only ~works in the next
`select` statement. And as when loading a user’s votes for investments
we do a second `select` it does not work as expected 😌

To solve this… we could call `set_random_seed` before loading a user’s
votes for an investment[2]

[1] #2131
[2]
https://github.com/AyuntamientoMadrid/consul/blob/master/app/controllers
/budgets/investments_controller.rb#L37
clairezed pushed a commit to CDJ11/CDJ that referenced this pull request Jun 26, 2018
…et-pagination-bug

Iagirre budget pagination bug
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.

None yet

3 participants