Hopeless Geek

Tagline

I’m in search of myself. Have you seen me?

Home » Blogs » Adam Knight's blog

A Little Drupal RSS Tip


  • Blogging
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.

  • Adam Knight's blog
  • Printer-friendly version

Post new comment

The content of this field is kept private and will not be shown publicly.
 
Input format
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Link to Amazon products with: [amazon product_id inline|full|thumbnail]. Example: [amazon 1590597559 thumbnail]
  • You can use Textile markup to format text.
  • Textual smileys will be replaced with graphical ones.
  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Link to Amazon products with: [amazon product_id inline|full|thumbnail]. Example: [amazon 1590597559 thumbnail]
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Textual smileys will be replaced with graphical ones.
  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Link to Amazon products with: [amazon product_id inline|full|thumbnail]. Example: [amazon 1590597559 thumbnail]
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Textual smileys will be replaced with graphical ones.
  • You may insert videos with [video:URL]

More information about formatting options

Syndicate content Syndicate content

Site Navigation

  • Home
  • Recent
  • Popular
    • Today
  • Top rated
    • Recent votes
  • Elsewhere
    • FriendFeed
    • Friends
    • Software
    • Unsane
View Adam Knight's profile on LinkedIn

Navigation

  • My votes

Recent comments

  • Do you have any idea as to
    4 days 4 hours ago
  • Absolutely amazing when you
    5 days 17 hours ago
  • I am pro-choice, but not for
    2 weeks 1 day ago
  • My apologies. It is your
    2 weeks 2 days ago
  • Well, first, get your own
    2 weeks 2 days ago
  • There is nothing mythical
    2 weeks 2 days ago
  • Well, the number of square
    2 weeks 5 days ago
  • I think you’re wrong by a
    2 weeks 5 days ago
  • I couldn’t agree more! I am
    2 weeks 6 days ago
  • I think those numbers are
    3 weeks 17 hours ago

Today's popular content

  • Careful, America... (93)
  • Krispy Kreme bacon cheddar cheeseburgers (5)
  • Panther's Major Text Services Upgrade (4)
  • Comment Spam Attack (3)
  • Now Hiring (3)
more

Hopeless Geek Feeds

  • Hopeless Geek
  • Hopeless Geek - Comments

Quotes

“Though the academic authorities are actually proud of conducting everything by means of Examinations, they seldom indulge in what religious people used to descibe as Self-Examination. The consequence is that the modern State has educated its citizens in a series of ephemeral fads.” — Nash’s Pall Mall Magazine. April, 1935 – G. K. Chesterton

Footer Links

  • Badges
  • Contact
Powered by Drupal, an open source content management system
© Adam Knight, All Rights Reserved except where otherwise noted.