CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Find who is running a monster query
Pages: [1]

Author Topic: Find who is running a monster query  (Read 612 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Find who is running a monster query
May 22, 2013, 09:19:42 am
Hi,

On one install, we have the site that goes down every couple of days with a mysql request eating all the cpu.

This is a 30 lines SELECT that, we assume, is generated either from an advanced search or a report.

We have asked the users and no one seems to be aware of them being the one triggering that query.

To help find the root of the problem, I've modified the queries to add the user name and ip address, so next time it goes crazy we'll know where to search.

on CRM/Core/DAO.php modify the query function
Code: [Select]
  function query($query, $i18nRewrite = TRUE) {
    // rewrite queries that should use $dbLocale-based views for multi-language installs
    global $dbLocale;
    if ($i18nRewrite and $dbLocale) {
      $query = CRM_Core_I18n_Schema::rewriteQuery($query);
    }

global $user;//XAVIER DEBUG
$debug = "WHERE ( 'user ".$user->name ."' = 'ip " .$_SERVER['REMOTE_ADDR']."' ) OR ";
$query = str_replace ("WHERE ",$debug,$query);

    return parent::query($query);
  }


So it adds in the query an OR name = ip criteria, that is obviously always OR false, so no impact on the query itself, but allows to see who has generated this query.

I'll amend once I found what is generating the query 
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Find who is running a monster query

This forum was archived on 2017-11-26.