#522 Bound the size of times, and read Markdown tables in linear time
–
- github
- github/openchronology/timeline-app
- github/openchronology/timeline-app#522
- pull request
- state:merged
**Times:** - **Unbounded by default:** exact rationals of any size remain a point of the product. The editor, the desktop app and the offline file keep times unbounded, within the 20,000 characters and ±10,000 exponents as before. - **Limited on a server:** a server limits the digits of a time's exact fraction in lowest terms, set by **`TIME_DIGIT_LIMIT`**: - empty or unset means `1000/65`, which is 10^-64 to below 10^1000 of the timeline's unit; - another limit is written ` / `, each from 20 to 1,000,000; - `unlimited` removes the limit, for a server whose writers are all trusted. - **Why a server limits them:** reading, comparing and summarizing fractions of thousands of digits takes a shared server minutes. - **How it's checked:** - `parseTime` (`src/core.ts`) counts the digits before any arithmetic and refuses times past the limit, naming it. - Request time bounds go through `parseTime` too. - The limit is read with the other limits at startup (`server/limits.mjs` `timeDigits`/`applyTimeDigits`), and an invalid value stops the server. - It's kept on the global object, so every bundled copy of core reads the one the server set. - **Existing data is unaffected:** the largest real timelines use 18 and 7 digits. - **Settings files:** `TIME_DIGIT_LIMIT` is added to `openchronology.env`, `.env.example` and `compose.yml`. **Saves:** a whole save (`PUT /api/timelines/{id}`) or a sparse one (`…/changes`) now checks that the account may write the timeline before reading the document. `store.save` still checks again under the timeline's lock. **Markdown:** - **Table delimiter rows:** a delimiter row (`| --- | :-: |`) is split at its pipes and each cell checked on its own, instead of one pattern over the line that could take cubic time. - **Trailing pipes:** `tableCells` checks for one with `trimEnd().endsWith('|')`. - **Excerpts:** `excerpt()` strips tags with `/<[^ ]*>/`, which can't rescan the text. - **Result:** both now take linear time on any input; tables render as before. **Tests:** - **`core.test.mjs`:** times are unbounded by default, as before. With the server's limit set, they're bounded and huge times are refused quickly. - **`limits.test.mjs`:** `TIME_DIGIT_LIMIT`'s values, the invalid ones it refuses, and applying it. - **`description-markdown.test.mjs`:** long crafted delimiter rows and runs of `<` are handled in well under a second, and tables read as before. - **Run locally, passing:** all unit tests (except `contents.test.mjs`, which fails on `main` in this checkout too), `postgres`, `next-postgres`, `save-merge`, `time-map`, `limits-postgres` and `next-platform`. **Docs:** - `docs/administration.md#how-large-a-time-may-be`; - `docs/time-presentation.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_011fFY8eruEi1xAkkMBni13B https://github.com/openchronology/timeline-app/pull/522
Related
Open #522 Bound the size of times, and read Markdown tables in linear time in the timeline