Commit 2e172b12 by Scott

Merge branch 'pr/246' into 1.8

Turned REPLACE statements into INSERT..ON DUPLICATE KEY UPDATE
parents f44ecd7f bf512912
...@@ -41,7 +41,8 @@ ...@@ -41,7 +41,8 @@
); );
qa_db_query_sub( qa_db_query_sub(
'REPLACE ^cache (type, cacheid, content, created, lastread) VALUES ($, #, $, NOW(), NOW())', 'INSERT INTO ^cache (type, cacheid, content, created, lastread) VALUES ($, #, $, NOW(), NOW()) ' .
'ON DUPLICATE KEY UPDATE content = VALUES(content), created = VALUES(created), lastread = VALUES(lastread)',
$type, $cacheid, $content $type, $cacheid, $content
); );
} }
......
...@@ -595,7 +595,9 @@ ...@@ -595,7 +595,9 @@
Set the current version in the database Set the current version in the database
*/ */
{ {
qa_db_query_sub("REPLACE ^options (title,content) VALUES ('db_version', #)", $version); require_once QA_INCLUDE_DIR . 'db/options.php';
qa_db_set_option('db_version', $version);
} }
......
...@@ -144,7 +144,8 @@ ...@@ -144,7 +144,8 @@
*/ */
{ {
qa_db_query_sub( qa_db_query_sub(
'REPLACE ^'.$metatable.' ('.$idcolumn.', title, content) VALUES ($, $, $)', 'INSERT INTO ^' . $metatable . ' (' . $idcolumn . ', title, content) VALUES ($, $, $) ' .
'ON DUPLICATE KEY UPDATE content = VALUES(content)',
$idvalue, $title, $content $idvalue, $title, $content
); );
} }
......
...@@ -32,7 +32,8 @@ ...@@ -32,7 +32,8 @@
*/ */
{ {
qa_db_query_sub( qa_db_query_sub(
'REPLACE ^options (title, content) VALUES ($, $)', 'INSERT INTO ^options (title, content) VALUES ($, $) ' .
'ON DUPLICATE KEY UPDATE content = VALUES(content)',
$name, $value $name, $value
); );
} }
......
...@@ -208,8 +208,13 @@ ...@@ -208,8 +208,13 @@
Update the cached count in the database of the number of rows in the userpoints table Update the cached count in the database of the number of rows in the userpoints table
*/ */
{ {
if (qa_should_update_counts()) if (qa_should_update_counts()) {
qa_db_query_sub("REPLACE ^options (title, content) SELECT 'cache_userpointscount', COUNT(*) FROM ^userpoints"); qa_db_query_sub(
"INSERT INTO ^options (title, content) " .
"SELECT 'cache_userpointscount', COUNT(*) FROM ^userpoints " .
"ON DUPLICATE KEY UPDATE content = VALUES(content)"
);
}
} }
......
...@@ -286,8 +286,14 @@ ...@@ -286,8 +286,14 @@
Update the cached count in the database of the number of questions (excluding hidden/queued) Update the cached count in the database of the number of questions (excluding hidden/queued)
*/ */
{ {
if (qa_should_update_counts()) if (qa_should_update_counts()) {
qa_db_query_sub("REPLACE ^options (title, content) SELECT 'cache_qcount', COUNT(*) FROM ^posts WHERE type='Q'"); qa_db_query_sub(
"INSERT INTO ^options (title, content) " .
"SELECT 'cache_qcount', COUNT(*) FROM ^posts " .
"WHERE type = 'Q' " .
"ON DUPLICATE KEY UPDATE content = VALUES(content)"
);
}
} }
...@@ -296,8 +302,14 @@ ...@@ -296,8 +302,14 @@
Update the cached count in the database of the number of answers (excluding hidden/queued) Update the cached count in the database of the number of answers (excluding hidden/queued)
*/ */
{ {
if (qa_should_update_counts()) if (qa_should_update_counts()) {
qa_db_query_sub("REPLACE ^options (title, content) SELECT 'cache_acount', COUNT(*) FROM ^posts WHERE type='A'"); qa_db_query_sub(
"INSERT INTO ^options (title, content) " .
"SELECT 'cache_acount', COUNT(*) FROM ^posts " .
"WHERE type = 'A' " .
"ON DUPLICATE KEY UPDATE content = VALUES(content)"
);
}
} }
...@@ -306,8 +318,14 @@ ...@@ -306,8 +318,14 @@
Update the cached count in the database of the number of comments (excluding hidden/queued) Update the cached count in the database of the number of comments (excluding hidden/queued)
*/ */
{ {
if (qa_should_update_counts()) if (qa_should_update_counts()) {
qa_db_query_sub("REPLACE ^options (title, content) SELECT 'cache_ccount', COUNT(*) FROM ^posts WHERE type='C'"); qa_db_query_sub(
"INSERT INTO ^options (title, content) " .
"SELECT 'cache_ccount', COUNT(*) FROM ^posts " .
"WHERE type = 'C' " .
"ON DUPLICATE KEY UPDATE content = VALUES(content)"
);
}
} }
...@@ -316,8 +334,14 @@ ...@@ -316,8 +334,14 @@
Update the cached count in the database of the number of different tags used Update the cached count in the database of the number of different tags used
*/ */
{ {
if (qa_should_update_counts()) if (qa_should_update_counts()) {
qa_db_query_sub("REPLACE ^options (title, content) SELECT 'cache_tagcount', COUNT(*) FROM ^words WHERE tagcount>0"); qa_db_query_sub(
"INSERT INTO ^options (title, content) " .
"SELECT 'cache_tagcount', COUNT(*) FROM ^words " .
"WHERE tagcount > 0 " .
"ON DUPLICATE KEY UPDATE content = VALUES(content)"
);
}
} }
...@@ -326,8 +350,14 @@ ...@@ -326,8 +350,14 @@
Update the cached count in the database of the number of unanswered questions (excluding hidden/queued) Update the cached count in the database of the number of unanswered questions (excluding hidden/queued)
*/ */
{ {
if (qa_should_update_counts()) if (qa_should_update_counts()) {
qa_db_query_sub("REPLACE ^options (title, content) SELECT 'cache_unaqcount', COUNT(*) FROM ^posts WHERE type='Q' AND acount=0 AND closedbyid IS NULL"); qa_db_query_sub(
"INSERT INTO ^options (title, content) " .
"SELECT 'cache_unaqcount', COUNT(*) FROM ^posts " .
"WHERE type = 'Q' AND acount = 0 AND closedbyid IS NULL " .
"ON DUPLICATE KEY UPDATE content = VALUES(content)"
);
}
} }
...@@ -336,8 +366,14 @@ ...@@ -336,8 +366,14 @@
Update the cached count in the database of the number of questions with no answer selected (excluding hidden/queued) Update the cached count in the database of the number of questions with no answer selected (excluding hidden/queued)
*/ */
{ {
if (qa_should_update_counts()) if (qa_should_update_counts()) {
qa_db_query_sub("REPLACE ^options (title, content) SELECT 'cache_unselqcount', COUNT(*) FROM ^posts WHERE type='Q' AND selchildid IS NULL AND closedbyid IS NULL"); qa_db_query_sub(
"INSERT INTO ^options (title, content) " .
"SELECT 'cache_unselqcount', COUNT(*) FROM ^posts " .
"WHERE type = 'Q' AND selchildid IS NULL AND closedbyid IS NULL " .
"ON DUPLICATE KEY UPDATE content = VALUES(content)"
);
}
} }
...@@ -346,8 +382,14 @@ ...@@ -346,8 +382,14 @@
Update the cached count in the database of the number of questions with no upvoted answers (excluding hidden/queued) Update the cached count in the database of the number of questions with no upvoted answers (excluding hidden/queued)
*/ */
{ {
if (qa_should_update_counts()) if (qa_should_update_counts()) {
qa_db_query_sub("REPLACE ^options (title, content) SELECT 'cache_unupaqcount', COUNT(*) FROM ^posts WHERE type='Q' AND amaxvote=0 AND closedbyid IS NULL"); qa_db_query_sub(
"INSERT INTO ^options (title, content) " .
"SELECT 'cache_unupaqcount', COUNT(*) FROM ^posts " .
"WHERE type = 'Q' AND amaxvote = 0 AND closedbyid IS NULL " .
"ON DUPLICATE KEY UPDATE content = VALUES(content)"
);
}
} }
...@@ -356,8 +398,14 @@ ...@@ -356,8 +398,14 @@
Update the cached count in the database of the number of posts which are queued for moderation Update the cached count in the database of the number of posts which are queued for moderation
*/ */
{ {
if (qa_should_update_counts()) if (qa_should_update_counts()) {
qa_db_query_sub("REPLACE ^options (title, content) SELECT 'cache_queuedcount', COUNT(*) FROM ^posts WHERE type IN ('Q_QUEUED', 'A_QUEUED', 'C_QUEUED')"); qa_db_query_sub(
"INSERT INTO ^options (title, content) " .
"SELECT 'cache_queuedcount', COUNT(*) FROM ^posts " .
"WHERE type IN ('Q_QUEUED', 'A_QUEUED', 'C_QUEUED') " .
"ON DUPLICATE KEY UPDATE content = VALUES(content)"
);
}
} }
/* /*
......
...@@ -351,8 +351,14 @@ ...@@ -351,8 +351,14 @@
Update the cached count of the number of flagged posts in the database Update the cached count of the number of flagged posts in the database
*/ */
{ {
if (qa_should_update_counts()) if (qa_should_update_counts()) {
qa_db_query_sub("REPLACE ^options (title, content) SELECT 'cache_flaggedcount', COUNT(*) FROM ^posts WHERE flagcount>0 AND type IN ('Q', 'A', 'C')"); qa_db_query_sub(
"INSERT INTO ^options (title, content) " .
"SELECT 'cache_flaggedcount', COUNT(*) FROM ^posts " .
"WHERE flagcount > 0 AND type IN ('Q', 'A', 'C') " .
"ON DUPLICATE KEY UPDATE content = VALUES(content)"
);
}
} }
/* /*
......
...@@ -207,8 +207,9 @@ ...@@ -207,8 +207,9 @@
*/ */
{ {
qa_db_query_sub( qa_db_query_sub(
'REPLACE ^userprofile (title, content, userid) VALUES ($, $, $)', 'INSERT INTO ^userprofile (userid, title, content) VALUES ($, $, $) ' .
$field, $value, $userid 'ON DUPLICATE KEY UPDATE content = VALUES(content)',
$userid, $field, $value
); );
} }
...@@ -293,11 +294,13 @@ ...@@ -293,11 +294,13 @@
$userid $userid
); );
foreach ($userlevels as $userlevel) foreach ($userlevels as $userlevel) {
qa_db_query_sub( qa_db_query_sub(
'REPLACE ^userlevels (userid, entitytype, entityid, level) VALUES ($, $, #, #)', 'INSERT INTO ^userlevels (userid, entitytype, entityid, level) VALUES ($, $, #, #) ' .
'ON DUPLICATE KEY UPDATE level = VALUES(level)',
$userid, $userlevel['entitytype'], $userlevel['entityid'], $userlevel['level'] $userid, $userlevel['entitytype'], $userlevel['entityid'], $userlevel['level']
); );
}
} }
...@@ -318,11 +321,15 @@ ...@@ -318,11 +321,15 @@
Update the cached count of the number of users who are awaiting approval after registration Update the cached count of the number of users who are awaiting approval after registration
*/ */
{ {
if ( qa_should_update_counts() && !QA_FINAL_EXTERNAL_USERS ) if ( qa_should_update_counts() && !QA_FINAL_EXTERNAL_USERS ) {
qa_db_query_sub( qa_db_query_sub(
"REPLACE ^options (title, content) SELECT 'cache_uapprovecount', COUNT(*) FROM ^users WHERE level<# AND NOT (flags&#)", "INSERT INTO ^options (title, content) " .
"SELECT 'cache_uapprovecount', COUNT(*) FROM ^users " .
"WHERE level < # AND NOT (flags & #) " .
"ON DUPLICATE KEY UPDATE content = VALUES(content)",
QA_USER_LEVEL_APPROVED, QA_USER_FLAGS_USER_BLOCKED QA_USER_LEVEL_APPROVED, QA_USER_FLAGS_USER_BLOCKED
); );
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment