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.
ps. Since http://drupal.org/node/166046 was sidelined due to being addressed to an out of date version, and the bug still remains, I'm resubmitting this, targeting the current 5.x-3.0 tree.
| Comment | File | Size | Author |
|---|---|---|---|
| privatemsg.30.logged_in_users_only.patch | 668 bytes | apotek |
Comments
Comment #1
apotek commentedTo make it clearer what the patch does, I'll print out the change here, so people don't have to download the patch and analyse.
Basically the patch changes the _privatemsg_get_new_messages() function so that requests for private messages for uid 0 don't happen (there's no point in getting private messages for a non-logged-in user.
So the code was:
And was changed to:
Comment #2
apotek commentedPerhaps another approach:
But I think there's something less clean about that. In some ways what we should be returning is a false for uid 0, but that would break the receiving code since it expects an int.
Comment #3
berdirI'm closing old issues since Privatemsg for Drupal 5 is not maintained anymore. I suggest you switch to Drupal 6 if possible, many of the reported issues are probably already resolved there and if not, you're welcome to open a new issue.