Back up my hard drive? I can’t find the reverse switch!

A Little Drupal RSS Tip

December 20, 2005 - 5:46pm

I noticed that Mac Geekery and codepoetry’s most-pulled files were RSS feeds. I’ve known that for a while, but just noticed it today. Funny that. So then I got to thinking about this fact and realized that for every pull of the feed (without caching) there’s a few dozen queries to be had. Even with caching there’s at least one query to be had. When you get 50K pulls of an RSS feed, that’s a lot of useless queries.

So, what follows is how to make a dynamic page static and updated so that Apache can do what it does best: send a static file.

As-is, the default rewrite rules for Drupal employ a basic test: let Apache send requests that exist, try to create requests that don’t. So, to get a static page in, just make the file exist. I used curl in my crontab to just pull the feed every 15 minutes and save that to a file:

*/15 * * * * curl -so /path/to/drupal/feeds/macgeekery.xml http://www.macgeekery.com/node/feed

Okay, so now I have my own static feed. To make Drupal point people to this, I made a path alias from node/feed to feeds/macgeekery.xml which made the link in the page header change instantly to this new location. Now I had a feed being pulled and Drupal was telling new people to use this feed. Great.

What do I do about the thousands of RSS subscribers? Apache can do this, easily. I added the following rules to Mac Geekery’s configuration right above Drupal’s rewrite rules:

RewriteCond %{REMOTE_ADDR} !^127
RewriteRule ^node/feed http://www.macgeekery.com/feeds/macgeekery.xml [L,R=permanent]

What this means, if you’ve never looked at rewrite rules before, is that only connections from IPs starting with 127 will get the real node/feed file; everyone else will get a redirect to the new feed location.

So, existing users get a redirect to the new location, new users get pointed to that location, cron makes sure the file is updated, and I’ve saved myself a few thousand SQL queries a day. Woo.

For extra points, I’m caching the blog feed in a few minutes, and then codepoetry’s feed.

Now, a curiosity: only NetNewsWire appears to automatically update itself when it gets a 301 response. Everyone else is either breaking or following the redirects every time. Rah rah to Ranchero, shame on everyone else.

“I agree with the realistic Irishman who said he preferred to prophesy after the event.” — ILN, 10/7/16 – G. K. Chesterton

Syndicate content