12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class SQLProfilePlugin extends Plugin
- {
- const PLUGIN_VERSION = '2.0.0';
- private $recursionGuard = false;
- public function onPluginVersion(array &$versions): bool
- {
- $versions[] = array('name' => 'SQLProfile',
- 'version' => self::PLUGIN_VERSION,
- 'author' => 'Brion Vibber',
- 'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/SQLProfile',
- 'rawdescription' =>
-
- _m('Debug tool to watch for poorly indexed DB queries.'));
- return true;
- }
- function onStartDBQuery($obj, $query, &$result)
- {
- if (!$this->recursionGuard && preg_match('/\bselect\b/i', $query)) {
- $this->recursionGuard = true;
- $xobj = clone($obj);
- $explain = $xobj->query('EXPLAIN ' . $query);
- $this->recursionGuard = false;
- while ($xobj->fetch()) {
- $extra = $xobj->Extra;
- $evil = (strpos($extra, 'Using filesort') !== false) ||
- (strpos($extra, 'Using temporary') !== false);
- if ($evil) {
- $xquery = $xobj->sanitizeQuery($query);
- common_log(LOG_DEBUG, "$extra | $xquery");
- }
- }
- }
- return true;
- }
- }
|