Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Stop skipping ages as they change unit
getElementsByClassName returns a live collection, so an age moved to
the next unit dropped out of it mid-loop and the age after it was
skipped until the next pass, which can be a day away. On a cached page
that has crossed a unit boundary every second age stayed stale.
querySelectorAll returns a static list of the same elements.
| -rw-r--r-- | assets/cgit.js | 2 | |
| -rwxr-xr-x | tests/t0005-markup.sh | 6 |
2 files changed, 7 insertions, 1 deletion
diff --git a/assets/cgit.js b/assets/cgit.js index 90f06c0..d09423f 100644 --- a/assets/cgit.js +++ b/assets/cgit.js @@ -67,7 +67,7 @@ function update_ages() { var now = Math.round(new Date().getTime() / 1000); for (bucket = 0; bucket < age_classes.length; bucket++) { - elements = document.getElementsByClassName(age_classes[bucket]); + elements = document.querySelectorAll("." + age_classes[bucket]); if (elements.length && update_delay[bucket] < delay) delay = update_delay[bucket]; diff --git a/tests/t0005-markup.sh b/tests/t0005-markup.sh index 5fa866d..1a8c5f2 100755 --- a/tests/t0005-markup.sh +++ b/tests/t0005-markup.sh @@ -162,6 +162,12 @@ test_expect_success 'the script waits for the page instead of holding it up' ' grep "<script src=./cgit.js. defer></script>" tmp ' +# A collection from getElementsByClassName is live, so an age the loop moves to +# another unit drops out of it at once and the age after it is skipped. +test_expect_success 'the script walks the ages from a list that holds still' ' + ! grep "getElementsByClassName" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.js" +' + # The rest of the hooks need a tag, a symlink, a submodule, a trailer, a lone # carriage return, clone urls, an empty repository and a second page of # repositories, so they get a commit and a config of their own after the checks |
