Today I Will Launch My Infant Son Into Orbit

2024-10-28

Implemementation Details

So I've been hemming and hawing over how to implement comments here for literal years.


Historically, this was not a hard problem, and at its base it really isn't one. The obvious solution is something like this (oh boy I'm doing uml diagrams in my free time now I can die!)

Simple UML diagram showing how a comments table could relate to a posts table

And that's cool, that's fine. In 1998, it's exactly what I and everyone else would have done. It also has some problems; for instance, in the design above, I've created a threading structure for comments (the parent comment ID) that posts don't have, so now there's special implementation details for comments exclusively. If I want to be able to attach comments to things other than posts or other comments, how do I do that? What if I want to support Webmention or Trackback? Should they be implemented by overloading comments or do I create yet another new taxonomy? And so maybe this needs a bit more thought.

Options!

First, I could just... do that, and it'll probably be fine. It's adding another database table and that means more specialized code (or I get to start refactoring the post handling in miniblog to abstract out things posts, pages and comments are all using) and I accept the limitations and risks above.

Second, and more ambitiously: Maybe I can syndicate comments to the Fediverse? Hell, maybe I can syndicate posts! That was my first idea a while back, and I started working on a Lisp implementation of the ninth circle of hell... I mean, of Activitypub. You'll notice that no such horror exists here, and that's because Activitypub is one of the worst protocols I've ever run into. It is, in the words of Douglas Adams, a product of a mind not just twisted but actually sprained. The idea that Activitypub is fit for any purpose whatsoever is truly comical, and yet here we are. So picking that back up is an option, but I don't currently hate myself enough to feel like I have a chance to actually do it. I also considered piggybacking on GoToSocial itself, and working via the public API; this is less Satanic than working on Apub directly but I still don't want to fucking do it.

Third: You know, those two tables in that UML diagram are really similar...

Comments are posts.

Oh hell yeah babey now we're getting somewhere.

This is what I settled on, and what I'm currently working on. This is a really pleasant option because it requires the tiniest of changes to my database schemas - just a self-reference column in the posts table - and it means I don't have to change pretty much anything else in the blog software except for filtering out posts with a listed parent in the general post display. That's fucking easy, man, and it's easily extensible to other cases. It would even allow - if I added some type information to the table - for pages to be collapsed into the single schema as well (since adding a parent reference gives us the same hierarchical structure pages already have), although that's going to be some work. Linkbacks could be treated as another type of post, or just done "as comments" but in a way that is easy to extend later.

And this is the real lesson: Try to keep your domain model as simple as possible. It's always easy to add complexity, but not so easy to reverse.

Comments

Test Comment

This is just a test comment, don't get excited

Posted by decay on Thursday, October 31st 2024 at 8:30 am PDT
Last updated by nobody on Saturday, November 2nd 2024 at 4:37 pm PDT

Response to test comment

Testing comment replies

Posted by decay on Saturday, November 2nd 2024 at 2:00 pm PDT
Last updated by nobody on Saturday, November 2nd 2024 at 4:37 pm PDT

Response to response test comment

Turtles all the way down dayo

Posted by decay on Saturday, November 2nd 2024 at 2:05 pm PDT
Last updated by nobody on Saturday, November 2nd 2024 at 4:37 pm PDT


Add New Comment



Posted by decay on Monday, October 28th 2024 at 11:22 pm PDT
Last updated by decay on Wednesday, October 30th 2024 at 2:17 pm PDT