Пример #1
0
 public function writeSolrLog($entry)
 {
     KalturaLog::debug("writeSolrLog " . $entry->getId());
     $solrLog = new SphinxLog();
     $solrLog->setEntryId($entry->getId());
     $solrLog->setPartnerId($entry->getPartnerId());
     $solrLog->save(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_SOLR_LOG));
 }
    if (is_null($entry)) {
        KalturaLog::err('Couldn\'t find entry [' . $entryId . ']');
        continue;
    }
    if ($entry->getViews() != $views || $entry->getPlays() != $plays) {
        $entry->setViews($views);
        $entry->setPlays($plays);
        KalturaLog::debug('Successfully saved entry [' . $entryId . ']');
        try {
            // update entry without setting the updated at
            $updateSql = "UPDATE entry set views='{$views}',plays='{$plays}' WHERE id='{$entryId}'";
            $stmt = $connection->prepare($updateSql);
            $stmt->execute();
            $affectedRows = $stmt->rowCount();
            KalturaLog::log("AffectedRows: " . $affectedRows);
            // update sphinx log directly
            $sql = $sphinxMgr->getSphinxSaveSql($entry, false);
            $sphinxLog = new SphinxLog();
            $sphinxLog->setEntryId($entryId);
            $sphinxLog->setPartnerId($entry->getPartnerId());
            $sphinxLog->setSql($sql);
            $sphinxLog->save(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_SPHINX_LOG));
        } catch (Exception $e) {
            KalturaLog::log($e->getMessage(), Propel::LOG_ERR);
        }
    }
    $count++;
    if ($count % 500 === 0) {
        entryPeer::clearInstancePool();
    }
}
 /**
  * @param string $sql
  * @param IIndexable $object
  * @return bool
  */
 public function execSphinx($sql, IIndexable $object)
 {
     KalturaLog::debug($sql);
     $sphinxConnection = null;
     $sphinxConnectionId = null;
     if (kConf::hasParam('exec_sphinx') && kConf::get('exec_sphinx')) {
         $sphinxConnection = DbManager::getSphinxConnection(false);
         $sphinxServer = SphinxLogServerPeer::retrieveByLocalServer($sphinxConnection->getHostName());
         if ($sphinxServer) {
             $sphinxConnectionId = $sphinxServer->getId();
         }
     }
     $sphinxLog = new SphinxLog();
     $sphinxLog->setExecutedServerId($sphinxConnectionId);
     $sphinxLog->setObjectId($object->getId());
     $sphinxLog->setObjectType(get_class($object));
     $sphinxLog->setEntryId($object->getEntryId());
     $sphinxLog->setPartnerId($object->getPartnerId());
     $sphinxLog->setSql($sql);
     $sphinxLog->save(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_SPHINX_LOG));
     if (!$sphinxConnection) {
         return true;
     }
     $sphinxConnection = DbManager::getSphinxConnection(false);
     $ret = $sphinxConnection->exec($sql);
     if ($ret) {
         return true;
     }
     $arr = $sphinxConnection->errorInfo();
     KalturaLog::err($arr[2]);
     return false;
 }
Пример #4
0
 /**
  * @param string $sql
  * @param IIndexable $object
  * @return bool
  */
 public function execSphinx($sql, IIndexable $object)
 {
     // limit the number of large sphinx SQLs to 1/min per object, since they load the sphinx database
     // and sphinx servers. the upper limit of 'slightly less than 1MB' is because of the max_allowed_packet
     // limit in mysql (by default 1MB). the upper limit is here to prevent the addition of too many category
     // users (for example), that will render the category un-indexable
     if (strlen($sql) > 128 * 1024 && strlen($sql) < 1000000) {
         $lockKey = 'large_sql_lock_' . get_class($object) . '_' . $object->getId();
         $cache = kCacheManager::getSingleLayerCache(kCacheManager::CACHE_TYPE_SPHINX_STICKY_SESSIONS);
         if ($cache && !$cache->add($lockKey, true, 60)) {
             KalturaLog::log('skipping sql for key ' . $lockKey);
             return;
         }
     }
     KalturaLog::debug($sql);
     $sphinxLog = new SphinxLog();
     $sphinxLog->setExecutedServerId($this->retrieveSphinxConnectionId());
     $sphinxLog->setObjectId($object->getId());
     $sphinxLog->setObjectType(get_class($object));
     $sphinxLog->setEntryId($object->getEntryId());
     $sphinxLog->setPartnerId($object->getPartnerId());
     $sphinxLog->setSql($sql);
     $sphinxLog->save(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_SPHINX_LOG));
     if (!kConf::get('exec_sphinx', 'local', 0)) {
         return true;
     }
     $sphinxConnection = DbManager::getSphinxConnection(false);
     $ret = $sphinxConnection->exec($sql);
     if ($ret) {
         return true;
     }
     $arr = $sphinxConnection->errorInfo();
     KalturaLog::err($arr[2]);
     return false;
 }
Пример #5
0
 /**
  * Declares an association between this object and a SphinxLog object.
  *
  * @param      SphinxLog $v
  * @return     SphinxLogServer The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setSphinxLog(SphinxLog $v = null)
 {
     if ($v === null) {
         $this->setLastLogId(NULL);
     } else {
         $this->setLastLogId($v->getId());
     }
     $this->aSphinxLog = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the SphinxLog object, it will not be re-added.
     if ($v !== null) {
         $v->addSphinxLogServer($this);
     }
     return $this;
 }
Пример #6
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      SphinxLog $value A SphinxLog object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(SphinxLog $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) {
             self::$instances[$key] = $obj;
             kMemoryManager::registerPeer('SphinxLogPeer');
         }
     }
 }
Пример #7
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      SphinxLog $value A SphinxLog object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(SphinxLog $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Пример #8
0
 /**
  * @param string $sql
  * @param IIndexable $object
  * @return bool
  */
 public function execSphinx($sql, IIndexable $object)
 {
     KalturaLog::debug($sql);
     $sphinxLog = new SphinxLog();
     $sphinxLog->setEntryId($object->getEntryId());
     $sphinxLog->setPartnerId($object->getPartnerId());
     $sphinxLog->setSql($sql);
     $sphinxLog->save(myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_SPHINX_LOG));
     if (!kConf::hasParam('exec_sphinx') || !kConf::get('exec_sphinx')) {
         return true;
     }
     $con = DbManager::getSphinxConnection();
     $ret = $con->exec($sql);
     if ($ret) {
         return true;
     }
     $arr = $con->errorInfo();
     KalturaLog::err($arr[2]);
     return false;
 }