Fix #304: Sort documents deterministically by name and lastModifiedAt #312
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix for GitHub Issue #304: Non-Deterministic Document Sorting
Summary
Successfully fixed the non-deterministic document sorting issue on the view-tournament page. Documents are now sorted alphabetically by name with
lastModifiedAtas a tiebreaker, ensuring consistent ordering across all scenarios.Problem Identified
Documents on the view-tournament page were being sorted by their
idfield (a GUID/PublicId) usinglocaleCompare(). Since GUIDs are randomly generated, this resulted in non-deterministic ordering where documents could appear in different orders across:Changes Made
view-tournament.component.ts
Updated the document sorting logic in two locations:
1.
togglePage()method (lines 258-263)Before:
After:
2.
reloadDocuments()method (lines 891-897)Before:
After:
Sorting Logic
The new sorting algorithm ensures deterministic ordering by:
localeCompare()This approach guarantees:
Technical Details
DocumentDto Model
The
DocumentDtointerface (from the backend) contains:id: PublicId (GUID) - Previously used for sortingname: string - Now used as primary sort keylastModifiedAt: DateTime - Now used as secondary sort keytype: DocumentTypetournamentId: PublicIdgenerationCount: numberWhy This Fix Works
lastModifiedAtprovides a consistent secondary sort for documents with identical nameslocaleCompare()ensures proper alphabetical sorting across different languages and character setsDocuments on the view-tournament page are now sorted alphabetically by name with lastModifiedAt as a tiebreaker, ensuring consistent ordering across all scenarios. Previously, documents were sorted by GUID-based IDs which resulted in non-deterministic ordering.