Taming slow rebuilds in Movable Type: An optimized Category Archive template

If you’re a user of Movable Type, listen up. Your rebuilds are getting slower. It takes users forever to post a comment. You’re getting frustrated.

The reason? The open-ended design of MT’s default Category Archive template. The solution? Peter R. Wood’s smarter Category Archives.

Why Category Archives in Movable Type are a problem

Here’s the story, in a nutshell:

  1. Movable Type ships with Category Archive templates that include the MTEntryBody of every entry in a given category.
  2. You, the ambitious blogger, begin to clog the Intarweb with worthless posts to your MT blog. These posts are archived to your category archives. These pages get huge.
  3. Each time you post an entry or your user comments on an entry, the category archive associated with that entry must be rebuilt. This means…
    • If you post an entry in Category A, which has 2 entries in it, it will rebuild quickly and won’t be a problem.
    • If you post an entry in Category B, which has 200 entries in it, it will take forever.
  4. You get more frustrated.
  5. Your users roll their eyes as they wait for category archive pages with 300 KB worth of text to load.

Peter R. Wood’s Category Archive tweak solves this. It’s the silver bullet. It’s creates (1) faster rebuilds and (2) more usable pages.

The idea

It’s very simple: Instead of including the entry body of everything in your category archives, do this for the last 10 entries. For everything else, just include the title and a link to the Individual Entry Archive. Not only does this improve rebuild time, it creates a smaller, friendlier page. You can see it in action at my category archives or Peter’s.

Some code for ya

Since everyone’s MT configuration is different, I’ll just include some pseudocode, generic-ish snippets here to get you on your way. In summary, the last few entries should include the MTEntryBody, while the rest should not. I did some informal testing to see whether rebuild times were affected by including comment- or trackback-specific tags, which I thought might increase rebuild time since they’re drawn from a separate table in MySQL, but this seemed to have a neglible effect. (If anyone here is more knowledgeable about the relationship between MySQL table structure and MT rebuild times, please speak up.)

<MTEntries lastn=”10″>

<h2><$MTEntryTitle$></h2>

<$MTEntryBody encode_ampersands=”1″$>

<MTEntryIfExtended>
<p><a href=”<$MTEntryPermalink$>”>Continue reading</a> &raquo;</p>
</MTEntryIfExtended>

<p>
<$MTEntryDate format=”%m/%d/%y”$> |
<a href=”<$MTEntryPermalink$>”>permalink</a>
<MTEntryIfAllowComments> | <a href=”<$MTEntryPermalink$>#comments”>comments [<$MTEntryCommentCount$>]</a></MTEntryIfAllowComments>
<MTEntryIfAllowPings> | <a href=”<$MTEntryPermalink$>#trackbacks”>trackbacks [<$MTEntryTrackbackCount$>]</a></MTEntryIfAllowPings>
</p>

</MTEntries>

<MTEntries lastn=”9999″ offset=”10″>

<p><$MTEntryTitle$></p>

<p>
<$MTEntryDate format=”%m/%d/%y”$> |
<a href=”<$MTEntryPermalink$>”>permalink</a>
<MTEntryIfAllowComments> | <a href=”<$MTEntryPermalink$>#comments”>comments [<$MTEntryCommentCount$>]</a></MTEntryIfAllowComments>
<MTEntryIfAllowPings> | <a href=”<$MTEntryPermalink$>#trackbacks”>trackbacks [<$MTEntryTrackbackCount$>]</a></MTEntryIfAllowPings>
</p>

</MTEntries>

Results

Since implementing this change, I’ve realized a 50-70% decrease in the time required to post a new entry, update an entry, or post a comment.

Other notes

I would also like to note that in a previous complaint about the slow rebuilding/MT Category Archive issue, I tagged the source of the problem as “poor application design.” That’s wrong. It has nothing to do with application design and everything to do with the default template.

Also, Anil Dash suggests converting only Category Archives to dynamic templates. This is a pretty good thought. It doesn’t work well for me because my MT installation is (a) very tweaked and much old-style plugin-driven and (b) extremely modular, wherein the Index, Date-Based, and Category templates reuse multiple components. However, for most users of MT—provided they’re pretty technically minded—this is an option.

Finally, if you are using dynamic publishing in MT, you should take a look at paginating via Smarty. This will get you the same kind of user-friendly pages that the above static template tweak affords. However, in my opinion, it’s hard to justify that much work with the minimal extra ROI.

7 Responses to “Taming slow rebuilds in Movable Type: An optimized Category Archive template”

  1. 1
    Peter Says:

    Glad you were able to make use of that tip! There are lots of other possibilities. For example, you could do an MTEntries with the most recent post in full, the 5 less recent posts as summaries, and all the rest of the posts as entry links. Etc, etc.

  2. 2
    Brian Behrend Says:

    I was having bandwidth issues because of the category templates. People were coming in via search engines and loading the entire archive with tons of images was killing me. I ended publishing just the excerpts (40 words or so) and using Paginate to handle the rest. Has worked pretty well for me in a static MT environment.

  3. 3
    Jack Vinson Says:

    One of my changes at the beginning of the year was to force myself to write excerpts for everything I write. My catgegory archives are now a listing of just the title and the excerpt with appropriate metadata. Still a little larger than your suggestion, but it makes me feel better.

  4. 4
    Naturelich Says:

    Quick Index on Category archives

    I have added an abbreviated index view for my category archives. Those category archive pages have become really long. As many entries in this blog contain one or more images, these archives cause a lot of network traffic on the…

  5. 5
    G'day Mate (Mk III) Says:

    Category Archives

    Given that I am using categories less in MT, the individual categories are getting huge (over 1700 entries in General) which means that things take a long time to rebuild and even longer to load when you click on the category archives….

  6. 6
    Shane Conder's Whateveritis of Nothing Says:

    Slowing Performance of Movable Type

    I was noticing today that saving a blog entry had started to get really slow. So, I did the natural thing. I googled about for others with similar issues. Minutes later, I found the following two sites: underscorebleach.net and Don’t…

  7. 7
    Straight to the Bar Says:

    Site updates : round 2

    Here’s a quick look at the second round of changes (first round here) to Straight to the Bar. Performance This site (and cousins on 99shadesofgrey.com) has been growing organically for several years now, and was starting to show signs of…