You are here

function radioactivity_process_memcached_entries in Radioactivity 5

Same name and namespace in other branches
  1. 6 radioactivity.module \radioactivity_process_memcached_entries()
1 call to radioactivity_process_memcached_entries()
radioactivity_cron in ./radioactivity.module

File

./radioactivity.module, line 411

Code

function radioactivity_process_memcached_entries() {
  $combined = array();

  // get newest memcache entry
  $entry_id_top = (int) dmemcache_get('entry_id_seq', 'radioactivity');
  $entry_id = dmemcache_get('entry_id_processed', 'radioactivity');
  if ($entry_id === FALSE) {
    $entry_id = $entry_id_top;
  }

  // check if entry_id_top has gotten flushed
  if ($entry_id_top < $entry_id) {
    $entry_id = 0;
  }
  while ($entry_id < $entry_id_top) {
    ++$entry_id;
    $entry = dmemcache_get('entry-' . $entry_id, 'radioactivity');
    if (!$entry) {
      continue;
    }

    // probably expired, try next
    switch ($entry['type']) {
      case 'add-energy':
        ++$combined[$entry['oid']][$entry['oclass']][$entry['source']];
        break;
      default:
    }
  }

  // execute combined
  foreach ($combined as $oid => $rest1) {
    foreach ($rest1 as $oclass => $rest2) {
      foreach ($rest2 as $source => $times) {
        _radioactivity_add_energy_internal($oid, $oclass, $source, $times);
      }
    }
  }
  dmemcache_set('entry_id_processed', $entry_id, 0, 'radioactivity');
}