So over time I've noticed my website getting slower and slower, normally at peak traffic hours and weekends - the CPU load would hit 10x what it should be and often the website would turn unresponsive.
After much hacking away at stuff, I've discovered commenting out this line brings the CPU load down to normalcy:
$this->file_hits++;
$this->weekly_file_hits++;
$this->daily_file_hits++;
$this->file_last_dl_ip = $downloader_ip;
$this->file_last_dl_time = current_time('mysql');
$wpdb->query("UPDATE " . $wpdb->wpfilebase_files
. " SET file_hits = file_hits + 1, weekly_file_hits = weekly_file_hits + 1, daily_file_hits = daily_file_hits + 1, file_last_dl_ip = '"
. $downloader_ip . "', file_last_dl_time = '"
. $this->file_last_dl_time . "' WHERE file_id = "
. (0+$this->file_id));
This is code from a WordPress plugin. It fires when a file is downloaded, and is pretty self explanatory, just logs hits/IP/date etc into the appropriate row in the DB.
I don't understand why this pretty simple update query would result in this?
Some info:
It looks like your UPDATE
query is running slowly. That could be because
file_id
column so WHERE file_id = something
can run faster in your UPDATE
. Is this the WP-Filebase plugin? If so, the usual advice to contact the plugin author doesn't apply, because the plugin has been closed by the wordpress.org authorities.
You are doing backups, right? If not, back up your database before doing anything else.
You need to fix up the slow table yourself. It's best to do this at a low-traffic time for your site.
Open up phpmyadmin, open your WordPress database, and look for a table with a name like wp_filebase_files
or wp_filebasefiles
. Click on the name. (I don't know exactly what the table name is.)
Then click the Operations tab at the top of your screen.
Then, under Table maintenance click the Optimize Table link. It may run for a while. Then see if performance improves. If that doesn't help, click the Repair Table link. Then try performance again.
If these don't help, you may need an index on your table. Here's how to add one.
On the left side of phpMyAdmin, click the [+] sign next to your table, then click the [+] signs next to Columns and Indexes.
If it shows file_id
as an index, you already have the index your query needs, and my advice can't help you. (Sorry.)
If it doesn't, click New under Indexes. You'll get a dialog box. Fill it out like this.
Then click Go. It may take a while to create the index. Then see if your performance picks up.
This kind of thing happens to busy databases; it's normal, but it's a pain in the neck.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.