You are here

function simplenews_statistics_get_url in Simplenews Statistics 7

Same name and namespace in other branches
  1. 7.2 simplenews_statistics.module \simplenews_statistics_get_url()

Gets an url record.

The caching causes a slight performance hit on our main task: redirecting users. But whilst generating/sending mails it gives us a huge performance gain though!

Parameters

string $url: Complete url to search for.

string $nid: Node ID that url should be for.

bool $reset: (optional) Reset cache for this URL.

Return value

object || FALSE Object representing the url record or FALSE.

1 call to simplenews_statistics_get_url()
_simplenews_statistics_replace_url in ./simplenews_statistics.module
Alter link to go through statistics.

File

./simplenews_statistics.module, line 344
Main simplenews statistics file.

Code

function simplenews_statistics_get_url($url, $nid, $reset = FALSE) {

  // We don't use the magic __FUNCTION__ as parameter because we want to use the
  // static cache outside the scope of this function as well. Mainly in the
  // simplenews_statistics_set_url() function.
  $cached_urls =& drupal_static('simplenews_statistics_url');
  if (!isset($cached_urls[$url]) || $reset) {
    $query = db_select('simplenews_statistics_url', 'ssu')
      ->fields('ssu', array(
      'urlid',
    ))
      ->condition('url', $url)
      ->condition('nid', $nid);
    $record = $query
      ->execute()
      ->fetchObject();
    if ($record !== FALSE) {
      $cached_urls[$url] = $record;
      return $record;
    }
  }
  elseif (isset($cached_urls[$url])) {

    // @todo: If multiple nodes are being sent simultaniously (e.g. by cron)
    // then we could in odd cases be returning the wrong urlid.
    return $cached_urls[$url];
  }
  return FALSE;
}