giza: Giza White Mage (Default)
[personal profile] giza
Earlier tonight, I was trying to figure out why a Drupal installation of mine was running kinda slow. So, I installed the awesome devel module and had it print out the list of database queries. What I found when going through the forums was on each post there were dozens and dozens of calls to drupal_lookup_path() for URLs which I never had (or will) make aliases of. Namely URLs that start with "comment/" or "user/".

So, I wrote a little patch for that function which will skip querying the database for URLs like that:

--- includes/path.inc   2007/09/14 00:06:12     1.1
+++ includes/path.inc   2007/09/14 00:15:21
@@ -44,6 +44,21 @@
   static $map = array(), $no_src = array();
   static $count;
 
+       //
+       // Drupal does an INSANE number of these queries for comment lnks
+       // and such on long threads, and that's just unacceptable.  Since
+       // I plan on like, never setting up a URL alias on a comment or 
+       // a user, I'm just going to stop here...
+       //
+       if (
+               stristr($path, "comment/")
+               || stristr($path, "user/")
+               ) {
+               return(false);
+       }
+
   // Use $count to avoid looking up paths in subsequent calls if there simply are no aliases
   if (!isset($count)) {
     $count = db_result(db_query('SELECT COUNT(pid) FROM {url_alias}'));


You will see the most gain with forum posts that have many comments, but even on regular pages you should see some benefit. Enjoy!

(no subject)

Date: 2007-09-14 04:33 am (UTC)
From: [identity profile] antimon.livejournal.com
and this is why i am not in programing. i don't speak computer.

Congrats on the find

(no subject)

Date: 2007-09-14 04:51 am (UTC)
From: [identity profile] tgeller.livejournal.com
So how do I implement this?

(no subject)

Date: 2007-09-14 01:16 pm (UTC)
From: [identity profile] giza.livejournal.com

Use the "patch" program.

It's usually a good idea to back up the original file first, though. RCS is great for this.

(no subject)

Date: 2007-09-15 12:28 am (UTC)
From: [identity profile] tgeller.livejournal.com
Thanks! I played with it for a minute but couldn't get it to work quickly, so I gave up. (I was probably running it from the wrong directory, or something.) Anyway, I'll revisit it if/when I have performance problems, or when we next talk.

Profile

giza: Giza White Mage (Default)
Douglas Muth

April 2012

S M T W T F S
1234567
891011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags