fix broken sort algorithm - #573
Open
btfcookies wants to merge 4 commits into
Open
Conversation
The bubble sort restarted its scan from the top after every single swap and
moved one row per pass, so reversing n rows cost O(n^2) DOM mutations. On the
set list (711 rows) that locked up the tab; measured under jsdom, reversing an
ordered table took 1.5 s at 100 rows, 30 s at 250, and over 90 s at 500.
Read the rows once, sort them with a comparator, and reinsert them through a
DocumentFragment so each row moves exactly once. The same table now reverses in
16-83 ms in the browser.
Three correctness fixes come with it:
- Cells that cannot be compared (blank text, or non-numeric text in a numeric
column) parsed to NaN. Every NaN comparison is false, so those rows never
swapped and no row could bubble past them, leaving the table sorted in
segments rather than as a whole. They now sort to the bottom in both
directions.
- Numeric columns sorted descending on the first click while text columns
sorted ascending. Every column now starts ascending.
- Direction was inferred by running an ascending pass and checking whether it
moved anything, so descending was only reachable from an already-sorted
column. The active column and direction are now recorded on the sorted
element as data-sort-column and data-sort-ascending, which callers can also
read to render header indicators.
Text now compares with Intl.Collator({ numeric: true }) so "Set 9" sorts before
"Set 10".
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016EPFeG9eLBDYimTx7ELc8b
The three count columns are filled with "-" placeholders by the first request
and only get real numbers from the second, much slower one. Clicking them
before that request lands sorted a column of placeholders, which did nothing at
all - no reorder, no feedback.
Those headers now start greyed out and unclickable, and become sortable when
the counts arrive. If that request fails they stay disabled rather than
offering a sort over data that never came; previously the failure was swallowed
entirely.
Also:
- Scope the header lookup to this table. document.querySelectorAll('th')
matched every header cell on the page, so a table added to the shared nav
would have shifted every column index and silently sorted the wrong column.
- Show which column is sorted and in which direction, via a caret and aria-sort
on the header. Direction is read back from the dataset that sortTable now
writes.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016EPFeG9eLBDYimTx7ELc8b
Contributor
Author
|
#563 can be closed if this is merged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pr is just an extension of #563 , i made a new one since there was a bunch of version control issues on 563. This fixes the
sortTablealgorithm at\client\scripts\utilities\tables.js.Fixes
parseFloatreturns NaN for any "-" placeholders that were added by\client\db\set-list\index.js.data-sort-column / data-sort-ascending.Testing
Note- /api/set-list?expand=true returns 50 sets instead of 711, which i believe is a bug introduced by #566 , I can investigate this further in a different pr if you would like.