SearchKit - Keep randomly sorted results stable across pages
authorColeman Watts <coleman@civicrm.org>
Thu, 23 Sep 2021 13:57:43 +0000 (09:57 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 23 Sep 2021 14:14:43 +0000 (10:14 -0400)
commit2eee38586eabb3f50d1ac094a8dbb5784137ff33
treea6cdc25812ad5674cd3eadf981787eab232c3470
parent29d047d701c7223e7999fc1f66381022c3dee0e7
SearchKit - Keep randomly sorted results stable across pages

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.
Civi/Api4/Query/SqlFunction.php
Civi/Api4/Query/SqlFunctionRAND.php
ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php
ext/search_kit/Civi/Api4/Action/SearchDisplay/Run.php
ext/search_kit/ang/crmSearchDisplay/traits/searchDisplayBaseTrait.service.js
ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php