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

SearchKit - A random stable genius #21586

Merged
merged 1 commit into from
Sep 26, 2021

Conversation

colemanw
Copy link
Member

Overview

Allows the pager, edit-in-place, and bulk updates to work properly with random sorting.

Before

You can do this, but it will cause strange behavior with the pager and inline/bulk updates. Results will appear randomly on each page, making the pager unusable, and a record will "disappear" immediately after inline-editing because it gets shuffled to a different spot.

Screenshot from 2021-09-23 10-07-41

After

Works as expected.

Technical Details

Without a seed, ORDER BY RAND() will reshuffle the results every time, whereas searchkit expects a stable order.

The solution is to generate a seed on the client-side when the display initializes, and re-use it every time results are fetched. This keeps the order stable, only reshuffling when the browser reloads the page.

@civibot
Copy link

civibot bot commented Sep 23, 2021

(Standard links)

@civibot civibot bot added the master label Sep 23, 2021
SearchKit allows ORDER BY RAND() but this can cause unexpected reshuffling
when using the pager, editing-in-place or bulk-updating records.

The solution is to generate a seed on the client-side when the display initializes,
and re-use it every time results are fetched. This keeps the order stable,
only reshuffling when the browser reloads the page.
@eileenmcnaughton
Copy link
Contributor

Seems to work - re-randomises on refresh but if I page back to the start it keeps the sort

@eileenmcnaughton eileenmcnaughton merged commit d95451d into civicrm:master Sep 26, 2021
@eileenmcnaughton eileenmcnaughton deleted the stableRandom branch September 26, 2021 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants