Beispiel #1
0
 /**
  * @return self
  */
 public static function getInstance()
 {
     static $instance;
     if (is_null($instance)) {
         $instance = false;
         if (Kwf_Config::getValue('debug.eventlog')) {
             $instance = new Kwf_Events_Log();
             $instance->resetTimer();
         }
     }
     return $instance;
 }
 public function onComponentAddedOrRemoved(Kwf_Component_Event_Component_Abstract $event)
 {
     $cacheId = 'procI-' . $event->component->getPageOrRoot()->componentId;
     Kwf_Cache_Simple::delete($cacheId);
     $log = Kwf_Events_Log::getInstance();
     if ($log) {
         $log->log("processInput cache clear componentId=" . $event->component->getPageOrRoot()->componentId, Zend_Log::INFO);
     }
 }
 public function onComponentAdd(Kwf_Component_Event_Component_Added $event)
 {
     $componentId = $event->component->componentId;
     $model = Kwf_Model_Abstract::getInstance(Kwc_Abstract::getSetting($this->_class, 'favouritesModel'));
     $select = new Kwf_Model_Select();
     $select->where(new Kwf_Model_Select_Expr_Equal('component_id', $componentId));
     $options = array('columns' => array('user_id'));
     $userIds = $model->export(Kwf_Model_Abstract::FORMAT_ARRAY, $select, $options);
     if ($userIds) {
         foreach ($userIds as $userId) {
             $componentIds = Kwf_Cache_Simple::fetch('favCIds' . $userId['user_id'], $success);
             if ($success) {
                 Kwf_Cache_Simple::delete('favCIds' . $userId['user_id']);
                 $componentIds[] = $componentId;
                 Kwf_Cache_Simple::add('favCIds' . $userId['user_id'], $componentIds);
                 $log = Kwf_Events_Log::getInstance();
                 if ($log) {
                     $log->log("favourites cache clear {$componentId}", Zend_Log::INFO);
                 }
             }
         }
     }
 }
Beispiel #4
0
 public static function fireEvent($event)
 {
     $logger = Kwf_Events_Log::getInstance();
     if ($logger && $logger->indent == 0) {
         $logger->info('----');
         $logger->resetTimer();
     }
     $class = $event->class;
     $eventClass = get_class($event);
     $cacheId = '-ev-lst-' . Kwf_Component_Data_Root::getComponentClass() . '-' . $eventClass . '-' . $class;
     $callbacks = Kwf_Cache_SimpleStatic::fetch($cacheId);
     if ($callbacks === false) {
         $listeners = self::getAllListeners();
         $callbacks = array();
         if ($class && isset($listeners[$eventClass][$class])) {
             $callbacks = $listeners[$eventClass][$class];
         }
         if (isset($listeners[$eventClass]['all'])) {
             $callbacks = array_merge($callbacks, $listeners[$eventClass]['all']);
         }
         Kwf_Cache_SimpleStatic::add($cacheId, $callbacks);
     }
     if ($logger) {
         $logger->info($event->__toString() . ':');
         $logger->indent++;
     }
     static $callbackBenchmark = array();
     foreach ($callbacks as $callback) {
         $ev = call_user_func(array($callback['class'], 'getInstance'), $callback['class'], $callback['config']);
         if ($logger) {
             $msg = '-> ' . $callback['class'] . '::' . $callback['method'] . '(' . Kwf_Debug::_btArgsString($callback['config']) . ')';
             $logger->info($msg . ':');
             $start = microtime(true);
         }
         $ev->{$callback['method']}($event);
         if ($logger) {
             if (!isset($callbackBenchmark[$callback['class'] . '::' . $callback['method']])) {
                 $callbackBenchmark[$callback['class'] . '::' . $callback['method']] = array('calls' => 0, 'time' => 0);
             }
             $callbackBenchmark[$callback['class'] . '::' . $callback['method']]['calls']++;
             $callbackBenchmark[$callback['class'] . '::' . $callback['method']]['time'] += (microtime(true) - $start) * 1000;
             //ATM includes everything which is missleading
         }
     }
     if ($logger) {
         $logger->indent--;
         if ($logger->indent == 0) {
             foreach ($callbackBenchmark as $cb => $i) {
                 $logger->info(sprintf("% 3d", $i['calls']) . "x " . sprintf("%3d", round($i['time'], 0)) . " ms: {$cb}");
             }
             $callbackBenchmark = array();
         }
     }
     self::$eventsCount++;
 }
 public function onMediaChanged(Kwf_Events_Event_Media_Changed $event)
 {
     Kwf_Media::clearCache($event->class, $event->component->componentId, $event->type);
     $log = Kwf_Events_Log::getInstance();
     if ($log) {
         $log->log("media cache clear class={$event->class} id={$event->component->componentId} type={$event->type}", Zend_Log::INFO);
     }
 }
Beispiel #6
0
 public function deleteViewCache($select, $progressBarAdapter = null)
 {
     $microtime = $this->_getMicrotime();
     $select->whereEquals('deleted', false);
     $model = $this->getModel();
     $log = Kwf_Events_Log::getInstance();
     $cacheIds = array();
     $options = array('columns' => array('component_id', 'renderer', 'type', 'value'));
     $partialIds = array();
     $deleteIds = array();
     $checkIncludeIds = array();
     $rows = $model->export(Kwf_Model_Abstract::FORMAT_ARRAY, $select, $options);
     $progress = null;
     if ($progressBarAdapter) {
         $count = count($rows);
         $steps = (int) (count($rows) * 2 / 100 + 3);
         $step = 0;
         $progress = new Zend_ProgressBar($progressBarAdapter, 0, $steps);
     }
     foreach ($rows as $key => $row) {
         if ($progress && $key % 100 == 0) {
             $step += 100;
             $progress->next(1, "viewcache {$step} / {$count}");
         }
         $cacheIds[] = $this->_getCacheId($row['component_id'], $row['renderer'], $row['type'], $row['value']);
         Kwf_Benchmark::countLog('viewcache-delete-' . $row['type']);
         if ($row['type'] != 'fullPage' && !isset($checkIncludeIds[$row['component_id']])) {
             $checkIncludeIds[$row['component_id']] = true;
         }
         if ($log) {
             $log->log("delete view cache {$row['component_id']} {$row['renderer']} {$row['type']} {$row['value']}", Zend_Log::INFO);
         }
         $type = $row['type'];
         $value = $row['value'];
         $cId = $row['component_id'];
         if ($type == 'partial' && $value != '') {
             if (!isset($partialIds[$cId])) {
                 $partialIds[$cId] = array();
             }
             $partialIds[$cId][] = $value;
         } else {
             if ($value == '') {
                 if (!isset($deleteIds[$type])) {
                     $deleteIds[$type] = array();
                 }
                 $deleteIds[$type][] = $cId;
             } else {
                 throw new Kwf_Exception('Should not happen.');
             }
         }
     }
     // Memcache
     $this->_beforeMemcacheDelete($select);
     // For unit testing - DO NOT DELETE!
     if ($progress) {
         $step = 0;
     }
     foreach ($cacheIds as $key => $cacheId) {
         if ($progress && $key % 100 == 0) {
             $step += 100;
             $progress->next(1, "memcache {$step} / {$count}");
         }
         Kwf_Component_Cache_Memory::getInstance()->remove($cacheId, $microtime);
     }
     $this->_afterMemcacheDelete($select);
     // For unit testing - DO NOT DELETE!
     // FullPage
     if ($progress) {
         $progress->next(1, "fullPage");
     }
     $s = new Kwf_Model_Select();
     $s->whereEquals('type', 'fullPage');
     if ($checkIncludeIds) {
         $ids = array_keys($this->_fetchIncludesTree(array_keys($checkIncludeIds)));
         if ($ids) {
             foreach ($ids as &$id) {
                 $id = (string) $id;
             }
             unset($id);
             $s->whereEquals('component_id', $ids);
             if ($log) {
                 foreach ($ids as $id) {
                     $log->log("type=fullPage component_id={$id}", Zend_Log::INFO);
                 }
             }
             $this->deleteViewCache($s);
         }
     }
     // Database
     $this->_beforeDatabaseDelete($select);
     // For unit testing - DO NOT DELETE!
     if ($progress) {
         $progress->next(1, "partialIds");
     }
     foreach ($partialIds as $componentId => $values) {
         $select = $model->select();
         $select->where(new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equals('component_id', (string) $componentId), new Kwf_Model_Select_Expr_Equals('type', 'partial'), new Kwf_Model_Select_Expr_Equals('value', $values), new Kwf_Model_Select_Expr_LowerEqual('microtime', $microtime))));
         $model->updateRows(array('deleted' => true), $select);
     }
     if ($progress) {
         $progress->next(1, "deleteIds");
     }
     foreach ($deleteIds as $type => $componentIds) {
         $select = $model->select();
         $select->where(new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equals('component_id', $componentIds), new Kwf_Model_Select_Expr_Equals('type', $type), new Kwf_Model_Select_Expr_LowerEqual('microtime', $microtime))));
         $model->updateRows(array('deleted' => true), $select);
     }
     $this->_afterDatabaseDelete($select);
     // For unit testing - DO NOT DELETE!
     if ($progress) {
         $progress->finish();
     }
     file_put_contents('log/clear-view-cache', date('Y-m-d H:i:s') . ' ' . round(microtime(true) - Kwf_Benchmark::$startTime, 2) . 's; ' . Kwf_Events_Dispatcher::$eventsCount . ' events; ' . count($deleteIds) . ' view cache entries deleted; ' . (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') . "\n", FILE_APPEND);
     return count($cacheIds);
 }
 private function _log($msg)
 {
     $log = Kwf_Events_Log::getInstance();
     if ($log) {
         $log->log("view cache clear {$msg}", Zend_Log::INFO);
     }
 }