themotte / rDrama

This code runs https://www.themotte.org. Forked from https://github.com/Aevann1/rDrama
GNU Affero General Public License v3.0
25 stars 30 forks source link

fix duplicate `~new~` indicators being sent #642

Closed justcool393 closed 1 year ago

justcool393 commented 1 year ago

consequently, we also make the JS we're generating about 7% the size it was before (a standard culture war thread would clock in about 1 MB of JS, we get this down to approximately 70 KB). fixes #608

justcool393 commented 1 year ago

A note on how the comment highlighting works. Because we're doing code generation, and most syntax highlighters don't like the intermingling of JS and Jinja, a comment is helpful here. Anyway, if we're on a post AND (a user is logged out or they have highlightcomments turned on) (this is code generated), we load the seen comment timestamp from localStorage.

We then create an array of array of (comment id and created timestamp (multiplied by 1000)) (from the db entries, this is code generated).

In JS, we filter this array (by the timestamp from localStorage) and map out just the IDs of the comments that are left, and only then mark them with the unread indicator.

Changes in this area: we check now to see if the unread CSS class is already present (if it is: we skip adding a ~new~. commentsAddUnreadIndicator() should now essentially be idempotent.

zorbathut commented 1 year ago

This fix looks good, but is there any way we could avoid the generated-JS entirely? Traverse over all the comment-[0-9]+ tags and just subsume those, rather than sending a database over?

I'm not sure what the performance on that would look like; it may not be practical.

zorbathut commented 1 year ago

Actually, y'know what, I'm going to check this in because it's already a lot better. If you want to tinker with a code-generation-less solution after this, go for it :)