T/sortable ids with b62 #47
Open
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.
Currently, task identifiers are generated using md5sum hashes. Since these hashes are not chronologically sortable, every time a new task is added it can end up in an arbitrary position in the task file.
To address this, I propose replacing the hash-based IDs with a monotonically increasing counter encoded in an obfuscated base62 ([0–9A–Z–a–z]) base. The counter starts at 62², so all generated IDs have at least three base62 digits, and is incremented every time a new task is created.
To preserve the IDs of existing tasks, I implemented a lookup table that maps each task’s hash to its current ID. When a task is processed, its hash is checked in this table:
if it already exists, the existing ID is reused;
if it does not exist, a new obfuscated base62 ID is generated from the counter, assigned to the task, and recorded in the lookup table.
For “summary line” tasks (those that can be added directly in a text editor without metadata), the first occurrence of such a task receives the next available ID (greater than all previous IDs). All subsequent tasks that follow this summary line receive IDs that are incremented from that point, ensuring that the chronological order of tasks in the file is consistent with their IDs.