Drupal

How to Speed up Drupal Forum Pages on a Busy Site

Drupal 5's forum module is OK. It lets you create multiple forums with taxonomy terms. Forum posts are true nodes so you get all the benefits of nodeness. And Drupal keeps track of which posts you've read. All that is great. But I've had some trouble scaling up a site that relies heavily on the forum module, even when using advcache. Investigating how the database was spending its time, I found lots of queries like this:

SELECT n.nid, n.title, n.sticky, l.comment_count, l.last_comment_timestamp FROM node n INNER JOIN node_comment_statistics l ON n.nid = l.nid INNER JOIN term_node r ON n.nid = r.nid AND r.tid = 123 WHERE n.status = 1 AND n.type = 'forum' ORDER BY n.sticky DESC, l.last_comment_timestamp desc

An EXPLAIN shows how nasty this is:

id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE n ref PRIMARY,node_type,status,node_status_type,nid node_status_type 102 const,const 30679 Using where; Using temporary; Using filesort
1 SIMPLE l eq_ref PRIMARY PRIMARY 4 drupal.n.nid 1  
1 SIMPLE r eq_ref PRIMARY,nid,tid PRIMARY 8 const,drupal.l.nid 1 Using where; Using index

Searching Drupal's code turns up this query in theme_forum_topic_navigation(). It turns out the database is smoking, grinding away, eating up cycles generating previous and next links for forum topics. I thought about it for a minute, and realized that I don't think I've ever used those links. Which would you rather have? Blazing speed or a link to the next forum topic? Fortunately, the slow query is in a themable function, which means we can get our performance back with a few lines added to our theme's template.php:

// No previous/next links for forum topics.
function phptemplate_forum_topic_navigation($node) {
  return '';
}

In my case, server load dropped from 46 to 0.5. Sometimes it's the little things.

Topic: 

Multistep Forms with Lookup Functions that Change Values

A number of people lately have been asking about how to change the values of form fields in multistep forms. So I wrote up an example.

Here we have a simple multistep form that lets you enter the name of a U.S. state, such as Iowa. Note the form has a default value.

Then, upon clicking the Lookup button, the value "Iowa" is replaced with a standardized state abbreviation, IA.

Upon submission both values are available to the submit function.

This example is not intended to do anything useful. It's just a little example that you can poke around with to learn how the sometimes confusing multistep form submission works in Drupal 5. You can download the module here.

Topic: 

FCKEditor toolbar will not appear - solution

When using FCKEditor as a WYSIWYG editor in Drupal, if you've double-checked all your settings and you can't get the formatting toolbar to appear, check to make sure that your template (e.g. page.tpl.php) is printing out the $closure variable. Thanks, latentdabbler.

Topic: 

Using Word 2007 Blog functionality to post to Drupal via the MetaWeblog API

First, I enabled the Blog API module on my Drupal site.

Then under Administer - Site Configuration - Blog APIs, I enabled the content type to which I want Word 2007 to publish to (just page in my case).

In Word 2007, I clicked on the round Office Button at the upper left of the screen and selected New.

I selected New blog post from the Microsoft Office Online template, then clicked the Create button.

I chose Other when asked about the provider:

I chose the MetaWebLog API, which Drupal supports. The Blog Post URL being requested is the URL of your site plus xmlrpc.php. The username and password are the Drupal username and password.

I am not exploring image support at this time, so I clicked on Picture Options and chose None - Don't upload pictures.

I then typed in my blog post and clicked the friendly Publish button in the Word 2007 Blog Toolbar, and...happy happy, my post appeared on my blog.

Topic: 

Pages

Subscribe to RSS - Drupal