Due to not-so-popular demand....
Started: Thursday, October 9, 2003 22:59
Finished: Thursday, October 9, 2003 23:10
A bunch of new code changes have just gone down the pipe. Among them, a threaded commenting system. Now, when you want to say something online in reaction to something said here, there's yet another place to do it! (As if there weren't enough options already.)
The other feature of note: Ghost Mode, available from the user preferences screen. I don't know how many will want to use it, but it was easy to add, so I figured, why not? If you have a login (or want a login), but don't want all the other users to be privy to your surfing habits, Ghost Mode is for you. For all intents and purposes, it turns you into a hidden user. (Except, of course, when you post something.)
The only catch? Ghost Mode users can't see the other people either. I figure that's a fair way to do it.
Comments, of course, are welcome. (Not to mention "there".)
There's actually more stuff I wanted to throw in with this "release", but the diff was getting big enough that I decided it was time to do an upload and commit before throwing in more.
I think I have way too much fun spending hours doing little tweaks to the most minor stuff. (CSS would be today's favorite. /me loves CSS.)
To reference a recent Yanthor quote, I'm hoping the user interface for this stuff (both already added and still to come) gets taken for granted a lot. :)
Now, a little more code tweaking before bed.
by Bitscape (2003-10-10 00:38)
Long ago, another content innovator told me about a scheme he had created that involved using floating point fields to retrieve an entire threaded comment tree using only a single sql query. When I questioned the wisdom of using floating point calculations, Yanthor said the floating point math more than made up for the time that would otherwise be used in executing a separate query for each nesting level, and challenged me to see if I could think of another way to do it.
I hereby present a code snippet or two from the lounge's thread code. A single simple query retrieves an entire thread tree, and perl code presents it in a nested format (some of the more mundane bits omitted for the sake of brevity):
I left out the actual comment_html function, as the only thing is does is return a string containing html populated by fields in the $comment hash reference.
Basic explanation: It runs a query which returns every comment associated with an article ordered chronoligically. It puts them into a data structure consisting of a hash whose keys are parent_id fields. The values are array references. Each array contains comments that are the direct children of the parent_id from the key of the hash.
In this way, the immediate children of any comment can be accessed through the array @{$self->{_comments}->{$parent_id}}.
Each member of that array is a reference to a simple old fashioned key => value hash, which contains the meat of the commment (body, subject, author, etc).
The following comment, which I put in the code to help ease my own conceptualization, might be of interest:
I use the recursive function show_tree() to pump out the thread itself.
So there it is. A single query to retrieve a threaded structure with no floating point math.
Biggest limitation: It does have to retrieve all the comments associated with the given article every time, so it can't use a query for just a given sub-thread using this method. (It could certainly be displayed that way, but the query would still grab the whole mess.) For my purposes at the moment, that limitation is a non-issue.
I love perl. (The same thing could be done in php using very similar means though.)
So now that I've probably bored and/or confused everyone who is still reading this to death, I'll wander off now. I suddenly find myself wishing I had implemented a preview feature, since I'm not sure how all this code mess is going to turn out on the page. Oh well. Here goes...