Skip to content

Commit

Permalink
optimize DatabaseObject - don't fetch adodb in every function
Browse files Browse the repository at this point in the history
  • Loading branch information
ahilles107 committed Apr 2, 2015
1 parent b41e2ba commit 082e83e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 14 additions & 11 deletions newscoop/classes/DatabaseObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class DatabaseObject
*/
var $m_oldKeyValues = array();

protected $ado_db = null;

/** @var EventDispatcher */
protected static $eventDispatcher = null;

Expand All @@ -80,6 +82,7 @@ class DatabaseObject
*/
public function DatabaseObject($p_columnNames = null)
{
$this->ado_db = \Zend_Registry::get('container')->get('doctrine.adodb');
if (!is_null($p_columnNames)) {
$this->setColumnNames($p_columnNames);
}
Expand Down Expand Up @@ -248,7 +251,7 @@ public function modifyKeyValue($p_columnName, $p_value)
*/
public function fetch($p_recordSet = null, $p_forceExists = false)
{
$g_ado_db = \Zend_Registry::get('container')->get('doctrine.adodb');
$g_ado_db = $this->ado_db;

if (is_null($p_recordSet)) {
if ($this->readFromCache() !== false) {
Expand Down Expand Up @@ -328,7 +331,7 @@ public function exists()
*/
public function getKeyWhereClause()
{
$g_ado_db = \Zend_Registry::get('container')->get('doctrine.adodb');
$g_ado_db = $this->ado_db;

$whereParts = array();
foreach ($this->m_keyColumnNames as $columnName) {
Expand Down Expand Up @@ -375,7 +378,7 @@ public function keyValuesExist($p_recordSet = null)
*/
public function create($p_values = null)
{
$g_ado_db = \Zend_Registry::get('container')->get('doctrine.adodb');
$g_ado_db = $this->ado_db;

$queryStr = 'INSERT IGNORE INTO ' . $this->m_dbTableName;

Expand Down Expand Up @@ -454,7 +457,7 @@ public function create($p_values = null)
*/
public function delete()
{
$g_ado_db = \Zend_Registry::get('container')->get('doctrine.adodb');
$g_ado_db = $this->ado_db;

$queryStr = 'DELETE FROM ' . $this->m_dbTableName
.' WHERE ' . $this->getKeyWhereClause()
Expand Down Expand Up @@ -500,7 +503,7 @@ public function delete()
*/
public function getProperty($p_dbColumnName, $p_forceFetchFromDatabase = false)
{
$g_ado_db = \Zend_Registry::get('container')->get('doctrine.adodb');
$g_ado_db = $this->ado_db;

if (in_array($p_dbColumnName, $this->m_columnNames) === false
&& !array_key_exists($p_dbColumnName, $this->m_data)) {
Expand Down Expand Up @@ -566,7 +569,7 @@ public function getProperty($p_dbColumnName, $p_forceFetchFromDatabase = false)
*/
public function setProperty($p_dbColumnName, $p_value, $p_commit = true, $p_isSql = false)
{
$g_ado_db = \Zend_Registry::get('container')->get('doctrine.adodb');
$g_ado_db = $this->ado_db;

// If we are not committing, the value cannot be SQL.
if (!$p_commit && $p_isSql) {
Expand Down Expand Up @@ -683,7 +686,7 @@ public function setProperty($p_dbColumnName, $p_value, $p_commit = true, $p_isSq
*/
public function update($p_columns = null, $p_commit = true, $p_isSql = false)
{
$g_ado_db = \Zend_Registry::get('container')->get('doctrine.adodb');
$g_ado_db = $this->ado_db;

// Check input
if (!is_array($p_columns)) {
Expand Down Expand Up @@ -761,7 +764,7 @@ public function update($p_columns = null, $p_commit = true, $p_isSql = false)
*/
public function commit($p_ignoreColumns = null)
{
$g_ado_db = \Zend_Registry::get('container')->get('doctrine.adodb');
$g_ado_db = $this->ado_db;

$setColumns = array();
foreach ($this->m_data as $columnName => $columnValue) {
Expand Down Expand Up @@ -800,7 +803,7 @@ public function commit($p_ignoreColumns = null)
*/
public static function Search($p_className, $p_columns = null, $p_sqlOptions = null)
{
$g_ado_db = \Zend_Registry::get('container')->get('doctrine.adodb');
$g_ado_db = $this->ado_db;

if (!class_exists($p_className)) {
return array();
Expand Down Expand Up @@ -1060,7 +1063,7 @@ public function getCacheKey($p_recordSet = null)

protected function lockTables(array $p_tables = array(), $p_write = true)
{
$g_ado_db = \Zend_Registry::get('container')->get('doctrine.adodb');
$g_ado_db = $this->ado_db;

if (count($p_tables) == 0) {
return;
Expand All @@ -1073,7 +1076,7 @@ protected function lockTables(array $p_tables = array(), $p_write = true)

protected function unlockTables()
{
$g_ado_db = \Zend_Registry::get('container')->get('doctrine.adodb');
$g_ado_db = $this->ado_db;

$unlockQuery = 'UNLOCK TABLES';
return $g_ado_db->Execute($unlockQuery);
Expand Down
2 changes: 1 addition & 1 deletion newscoop/template_engine/metaclasses/MetaArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ protected function getTopics()
protected function getSEOURLEnd()
{
$cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
$cacheKey = $cacheService->getCacheKey(array('seo_url_end', $this->m_dbObject->getProperty('IdPublication')), 'publication');
$cacheKey = $cacheService->getCacheKey(array('seo_url_end', $this->m_dbObject->getProperty('Number'), $this->m_dbObject->getProperty('IdLanguage')), 'article');
if ($cacheService->contains($cacheKey)) {
return $cacheService->fetch($cacheKey);
}
Expand Down

0 comments on commit 082e83e

Please sign in to comment.