Thinking aloud about Typo
Unless you’re interested in the internals of the Typo blogging engine and a possible rejigging of it, don’t bother reading the rest of this.
Typo Content Models
I’ve been attempting to follow the DRY Principle and rejigging Typo so that there’s fewer places with similar code to handle the cached html associated with a content object. Also, I’ve been thinking of how to build a more intelligent cache sweeper — at the moment, if you change a single article, every page in the cache is removed, which isn’t ideal. To that end I wrote a ContentModel mixin that adds a new class method:
class Article < ActiveRecord::Base
include ContentModel
content_fields :body, :extended
...Declaring a content_field sets up a setter method that would notify any object observers that the content has changed and reset the associated _html attribute.
Which is all very well, but I think the time might have come to make a Content superclass. The various typo content models already have quite a few fields in common, and even Article, the ‘biggest’ of them doesn’t have too many unique fields, so using Single Table Inheritance a completely insane idea.
What does that buy us?
- Conceptually, it buys us a neater model, albeit at the expense of a slightly scruffier table structure (Rails can’t do multi-table inheritance yet).
- A unified ID scheme for our content models means that any putative table mapping content objects to currently cached files is going to be substantially simpler.
- Threading. Add
parent_idcolumn to the table and, because of the uniform ID structure, a comment gets to have a parent that is either an Article, another Comment or (possibly) a Trackback.
How could it hurt?
- The database table’s a bit scruffier.
- Writing the migrations could be fun.
- We’d have to make sure that the old
articles/read/idURLs continued to work — Adding anold_idcolumn is one way forward, but it strikes me that a better way to do it would be to extend thearticlestable until it had all the fields required then rename it appropriately and then copy all the other content objects into it.
Conclusions
Well, I think it’s worth doing. But it’s my idea, so I would say that wouldn’t I. If you’re a Typo person and you’re reading this, what do you think?
