Developer Update: Updated Comment System (Patreon)
Content
Updating Comments
Updating comments has been a long time goal of mine. There a are a lot of things that users couldn't do like reply to a specific user, add hearts and trashes to a specific message, etc.
I looked at a lot of systems but I'm hesitant to bring in third party solutions like disqus, and popular ones like commento look like a pain in the ass to manage. Other ones which support auto-sign in for commenting are also very expensive. I spent most of my saturday crafting out a solution that I think will work.
A comment system is an NP hard problem. There are things like nested data sets that you can store in MYSQL, but I don't want a ton of bloat for what amounts to a rather under-utilized feature. What I ended it doing is taking a modified approach using a flat structure and using a materialized path approach.
Each comment will be storing a path, so, if its a reply to another comment, it will store a path that looks like:
parent_path . my_id
so, if a comment is replying to comment_id 10, it will be:
parent_id: 10
path: 10, 11
The drawback is that when reading from the database I must read the whole entirety of the comments and assemble them. I'll be writing some seeds to seed about 40,000 comments so I can test it out, but I don't believe it will be an issue. It appears to be quite fast, though, as the tree is made in a single pass. It will parse the path and jump down the nodes by jumping into "children" in between nodes. If it finds a child that is not set, then, that child is the comment we're on.
The second thing it will do is take the original flat structure and order by the comment date. From there, it will take the first node from the path and make a secondary list of order. This will be passed to the frontend so it can bubble up root nodes that have the most recent comments and show them first. I'm still working out the cutoff for these as after a certain point, we really only need to order the first X nodes since most waifus, even the most popular, don't get too many comments per day. Even 100 should be alright. I'm pretty happy with the result so far.
Redone File Attachments
One thing I noticed on other websites is that images are inline, but full. We allowed emotes or small images in the past, but this did not yield the result I wanted. I wanted users to be able to attach larger reaction pics in png, jpg, etc, or potentially GIFFY. For now, I added a small image upload into this that accepts still images up to 1mb (i will compress them of course) and these images will be appended up to a width, height of 600 while maintaining aspect ratio below the post itself.
And with the reply chain, nested replies:
Hearts, Trash
I wanted users to be able to rank comments by heart and trash as well so we can display popular comments at the top for some waifus. I will be adding sorting by popular OR most recent as a result. I am still working on optimizing the likes, trash as far as the DB layer but I really think it's a step in the right direction for user interaction.
I will keep working on this and polishing things up, checking performance, and with any luck it should be out in the next few weeks!
Thank you for your continued support <3