Add default order by ID to API list queries#7424
Conversation
|
What about adding a default scope to all What do you think? |
|
@mrcasals Yes, I was thinking the same but there are some problems with that:
So, if you have ideas how to do that, let me also know. |
|
@ahukkanen we could overwrite the Let's stick with your solution for now! |
|
I'm rerunning the generators job! |
|
@mrcasals Overriding The only way to achieve this reliably would be to override the I would suggest against that as it's probably going to be way easier to just fix it case by case where it needs to be fixed, e.g. in the admin listing views that you mentioned. The proposals admin view, for example, is already sorted by |
Only if the component is configured as a participatory text component, otherwise it doesn't seem to be ordered. But anyway, let's not dig into overwriting stuff, since it's a source of problems, and as you say let's fix the issues one by one. This PR is a nice start! |
|
It seems there's an issue with the generators, I'll merge this PR since the code doesn't affect it and fix the issue in a different PR. |
Yeah, true that. For the admin case I believe it is still rather easy to fix: (this is where all the filterable admin views get their results from) And this is how you can add default sorting with that: |
|
Thanks for checking this out! I'll try to find time to work on this, but I can't promise a date. Let me open an issue to track it! |
* develop: (232 commits) Add Votings to Open Data export (#7388) Add order in not highlighted assemblies by weight (#7444) Resort Menus (#7460) Polling Officer Zone (#7439) Fix session timeout when using multiple windows or tabs (#7459) Fix display of debates with multiple dates (#7393) chore: split election tests (#7451) style: make selected values primary labels with delete button (#7448) Fix and tests to avoid registered users being invited again (#7392) Migrate Admin menus to Menu Registry (#7368) New Crowdin updates (#7338) Bump to carrierwave 2.2.0 (#7441) Voting: show callout when Polling Stations miss Polling Officers (#7417) Further default orders for the API (#7436) Fix random order inconsistencies (#7437) Ensure Rails is locked to 5.2.4.x series (#7430) Add default order by ID to API list queries (#7424) Update dependencies (#7422) Ignore warning on CI when no artifacts to upload (#7420) Filter and search polling officers (#7411) ...
🎩 What? Why?
Currently the list queries in API are not working consistently because they do not define a default order for the query. This can be seen especially when you have multiple pages of records in the API.
PostgreSQL works in mysterious ways but recently we discovered that the default sort order can be randomly changed in case the records are updated. This affects the API list queries in case we have multiple pages of records. If the following happens, we can expect random ordering and possible duplicates between the different pages of the records:
To fix this problem, let's add a default order by ID to the API list query. This won't affect the queries that have defined order through the GraphQL query, as it will be added at the last stage of the query when it becomes a secondary sort criteria in case there is already another sort criteria added before it.
Testing
decidim_proposals_proposalstable's records selected randomly. It does not matter what the update is (you could update e.g. theupdated_atcolumn), as long as it's done against the main table being queried through the API.If the API fetching ends too fast, increase the amount of records in the DB. If you didn't receive any duplicates (or missing records), re-run the scripts as many times as you will bump into the issue.
📋 Checklist
docs/.