dayjobfinder

Topic: CheckPosterEmail is killing my server

Hi, I've been running jobberbase for a few months now, and I like it quite a bit. I've started getting a lot of traffic to it (5 - 10,000 visitors/day) and my job database is getting quite large (around 6,000 jobs).

I think I'm really starting to push the tool to its limits because it's really taking a large toll on my server - I have some ideas why and I've actually started optimizing several of the queries . . . but there's one I can't figure out.

In /_includes/class.Job.php there's a function called CheckPosterEmail() that looks like this . . .

--
// Check if the poster of this post has posted before with this e-mail address
    public function CheckPosterEmail()
    {
        global $db;
        $sql = 'SELECT poster_email FROM jobs
                          WHERE poster_email = "' . strtolower($this->mPosterEmail) . '" AND id <> ' . $this->mId . ' AND is_temp = 0
                                AND (is_active = 1 OR (is_active = 0 AND DATEDIFF(NOW(), created_on) > 30))';
        $result = $db->query($sql);
        $row = $result->fetch_assoc();
        if (!empty($row['poster_email']))
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
--

And when I go through my slow query logs on my server, I see that this particular process goes crazy from time to time - in fact it has run over 15,000 times in the 15 minutes I've been poking around on this forum for an answer to why it might be running so many times.

Any ideas why it would be called so many times? It looks to me like it should only be called when someone posts a new job to my site (which hasn't happened 15,000 times in the past 15 minutes - maybe only three or four times).

Your help will be appreciated.

putypuruty

Re: CheckPosterEmail is killing my server

Hi.

I've had some time to test this issue and it's indeed a performance problem - CheckPosterEmail() is called even when it shouldn't be.

This is what you have to do in order to fix it:

1. Open page_publish.php and replace line 6 ($nicu->MailPublishToAdmin($job->GetInfo())wink
with

Code:
$jobInfo = $job->GetInfo();
$jobInfo['check_poster_email'] = $job->CheckPosterEmail();
    
$nicu->MailPublishToAdmin($jobInfo);

2. Open _includes/class.Job.php and remove this line (around line 120) 'check_poster_email' => $this->CheckPosterEmail(), from inside public function GetInfo()

This should do it (I've tested it and it should work without any side effects).

Thanks for bringing it to our attention.