Created
September 7, 2012 18:32
-
-
Save johnciacia/3668413 to your computer and use it in GitHub Desktop.
QA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* In wp-config.php: define WP_DEBUG and SAVEQUERIES to true | |
* Add this code to the bottom of wp-config.php or functions.php | |
*/ | |
add_action( 'shutdown', function() { | |
if( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) { | |
global $wpdb; | |
echo "<pre id='queries'>"; | |
echo json_encode($wpdb->queries); | |
echo "</pre>"; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/Users/john/qa.py | |
RESULT=$? | |
if [ $RESULT -ne 0 ]; then | |
echo | |
echo "QA Failed. Please optimize your queries." | |
exit 1 | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import urllib2 | |
import re | |
import json | |
import sys | |
# Set the domain to the domain name you would like to check - bigten.staging.voceconnect.com | |
domain = '' | |
# Add any paths you would like to benchmark | |
paths = ['/', '/about/', '/archives/', '/?s=hello', '/category/', '/'] | |
FAIL = 0; | |
print "Priming the cache..." | |
for path in paths: | |
# TODO: Add support for basic authentication | |
response = urllib2.urlopen('http://' + domain + path) | |
html = response.read() | |
data = re.search("<pre id='queries'>(.*)</pre>", html) | |
queries = data.group(1) | |
q = json.loads(queries) | |
print path | |
print "\n" | |
for path in paths: | |
response = urllib2.urlopen('http://' + domain + path) | |
html = response.read() | |
data = re.search("<pre id='queries'>(.*)</pre>", html) | |
queries = data.group(1) | |
q = json.loads(queries) | |
if len(q) < 20: | |
print '[\033[92mPASS\033[0m] ' + str(len(q)) + ' ' + path | |
else: | |
print '[\033[91mFAIL\033[0m] ' + str(len(q)) + ' ' + path | |
FAIL = 1 | |
sys.exit(FAIL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment