By inserting an error_log() statement in the _privatemsg_get_new_messages(), I saw that the database query (SELECT COUNT(*) FROM {privatemsg} WHERE recipient = %d AND newmsg = 1 AND recipient_del = 0) was being run whether I was logged in or not.

This doesn't make sense. There's no point in doing this query if the user is anonymous/not logged in.

I have written a patch to fix this. I'm sure there's a more "Drupal" way to do this, but I don't know all the ins and outs. This works, and maybe with a cleanup or two we can be on our way to saving privatemsg.module users a TON of unecessary db queries.

Thanks.

Comments

czarphanguye’s picture

nice.

Roman S’s picture

Version: 4.7.x-1.3 » 5.x-3.0

This problem still exists in the latest code. Moreover, every call to a non-page resource on the server (using private files) hits the DB as well!

Roman S’s picture

Version: 5.x-3.0 » 4.7.x-1.3

Changing version back, since that's what the original patch was for...

apotek’s picture

Status: Needs review » Closed (duplicate)

Okay, I submitted a patch for the 5.x-3.0 version instead. So this is now an out-of-date duplicate of that bug. Please see http://drupal.org/node/357783