Skip to content

Keep the calendar's linked-doc reader fast on long runs of blank lines - #2068

Open
svaka2000 wants to merge 1 commit into
Open-Coding-Society:mainfrom
svaka2000:fix/doc-link-regex
Open

svaka2000 wants to merge 1 commit into
Open-Coding-Society:mainfrom
svaka2000:fix/doc-link-regex

Conversation

@svaka2000

Copy link
Copy Markdown
Contributor

This keeps an event with a long run of blank lines (newlines or <br> tags) in its description from freezing a course home. Like #2060, it's about event text any signed-in account can write. Since #2061, the ticker on course homes reads each upcoming event's description to find its linked doc, the Linked doc: <url> line at the end.

  • It only matters if Spring can save a description longer than 255 characters. The column is varchar(255), which MySQL enforces but SQLite doesn't, and Spring's code doesn't check the length. Spring uses SQLite when DB_URL isn't set, and its README says production is on SQLite right now.
  • splitLinkedDoc in _projects/systems/calendar/js/CalendarDocLinks.js used one regex for the doc line and the blank lines before it. When the doc line didn't come right after a long run of blank lines, it started over at each one and read to the end of the run, so twice the lines took about four times as long.
  • Now the regex only matches the Linked doc: line, and a small loop takes the same whitespace and <br> tags off the end of the text before it, reading each one once.
  • It gives the same results as before, so existing events work the same. I compared it with main's version on 500,000 random descriptions of newlines, spaces, <br> tags, links and Linked doc: lines, and they all split the same way.
  • The only other place that calls it is the calendar page (/student/calendar), when you open an event and again when you click Edit, so it had the same problem.

Other notes:

  • I tried both pages on the live site in Chrome with Playwright. Spring and Flask were faked, with one event that had 200,000 blank lines in the middle of its description, and the page got either main's or this branch's CalendarDocLinks.js.
  • With main's file, the CSA course home froze for about a minute before the ticker showed up. The calendar page froze for about a minute when I opened the event, and again when I clicked Edit.
  • With this branch's file, each of those took under a second, and the ticker had the same items and links.
  • I added tests to _projects/systems/calendar/tests/doc_links.test.mjs: long runs of blank lines have to split in under 100 ms, the doc line is still found after them, and <br/>, <br /> and <BR> count as line breaks. With main's version the speed test failed after about a minute.
  • node --test tests/calendar_doc_links.test.mjs tests/calendar_ticker.test.mjs tests/calendar_safe_html.test.mjs passes.
  • It's only a Pages change. I added a sentence about it to the calendar part of AGENTS.md and AGENTS_MD_DOCUMENTATION.md.

How to try it:

  1. Check out fix/doc-link-regex from svaka2000/Pages-JJ.
  2. Run node --test tests/calendar_doc_links.test.mjs. It passes in under a second.

The old pattern started with the blank lines before the doc line, so from inside a long run of them it re-read the run at every position: 200,000 blank lines took about a minute. Now it matches only the doc line and trims the blank lines before it from the end.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant