Table of Contents

Zeitgeist patch

On 2005-11-29, I suggested a patch to search to allow search to create a block listing recent searches.

Ensuing discussion on #drupal and on the patch page suggested that:

I looked deeper into this and I think that making this feature more resilient would involve changing watchdog. The idea is therefore as documented below.

As this involves changes to core features, I hope developers with a deeper understanding of core than me will comment on this/edit this page to improve it before I write code involving these core changes. The wiki structure allows this more easily than comments on the patch page.

Problems with the current patch

If you look at the patch, what it basically does is this, along with the definition of a new block in search_block:

function _search_recent()
  {
  $sq = "
  SELECT
    distinct message query
  FROM
    {watchdog}
  WHERE
    (type = 'search') AND (message like '%(content).')
  ORDER BY timestamp DESC
  " ;
  $q = db_query_range($sq, 0, 5);
  $ar = array();
  while ($o = db_fetch_object($q))
    {  
    $term = substr(substr($o->query, 12),0,-16);
    $ar[] = l($term, 'search/node/' . $term);
    }
  $output = theme_item_list($ar, NULL);
  unset ($ar);
  return $output ;
  }

You'll notice the “substr” line is dependent of the current format of the watchdog entries, which means it will most likely break on any translated site. And I know drupal style does not like multiline queries.

Also, processing is done in PHP whereas a better implementation would just ask the DBMS for the set of distinct entries in proper order to minimize the global workload.

Changes to watchdog

function watchdog(
  $type, 
  $message, 
  $severity = WATCHDOG_NOTICE, 
  $link = NULL,
  $data = NULL) {

The new parameter could be used by modules aware of this new feature to store content of their choice in the watchdog along with the standard parameters, while retaining compatibility with existing call through the use of a default NULL.

In the current 4.6.x core, only watchdog module queries the watchdog table, and does so with queries like:

SELECT w.* [...] FROM {watchdog} w

which means no outside modules should be impacted. These queries could be improved to avoid querying this additional column if it is not needed.

TODO

2005-11-29 8:33 chx says:

If you want to win the developers' hearts then you change the trigger_error in _db_query to a watchdog call (avoid infinite loops! keep a static var about 'tried watchdog it') which stores the debug_backtrace and lift the debug_backtrace renderer from devel. The latter is a contrib module but this would be just great, i think two lines o' code and would make drupal a hell lot easier to debug.

2005-1129 20:33 After further discussion, it looks like the idea is to log the debug_backtrace() information in the additional field.