Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model performance improvements #646

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions source/Application/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -976,22 +976,24 @@ protected function _update()
/**
* Sets data field value
*
* @param string $sFieldName index OR name (eg. 'oxarticles__oxtitle') of a data field to set
* @param string $sValue value of data field
* @param int $iDataType field type
* @param string $fieldName index OR name (eg. 'oxarticles__oxtitle') of a data field to set
* @param string $value value of data field
* @param int $dataType field type
*
* @return null
*/
protected function _setFieldData($sFieldName, $sValue, $iDataType = \OxidEsales\Eshop\Core\Field::T_TEXT)
protected function _setFieldData($fieldName, $value, $dataType = \OxidEsales\Eshop\Core\Field::T_TEXT)
{
//preliminary quick check saves 3% of execution time in category lists by avoiding redundant strtolower() call
if ($sFieldName[2] == 'l' || $sFieldName[2] == 'L' || (isset($sFieldName[16]) && ($sFieldName[16] == 'l' || $sFieldName[16] == 'L'))) {
if ('oxlongdesc' === strtolower($sFieldName) || 'oxcategories__oxlongdesc' === strtolower($sFieldName)) {
$iDataType = \OxidEsales\Eshop\Core\Field::T_RAW;
$fieldNameIndex2 = $fieldName[2];
if ($fieldNameIndex2 === 'l' || $fieldNameIndex2 === 'L' || (isset($fieldName[16]) && ($fieldName[16] == 'l' || $fieldName[16] == 'L'))) {
$loweredFieldName = strtolower($fieldName);
if ('oxlongdesc' === $loweredFieldName || 'oxcategories__oxlongdesc' === $loweredFieldName) {
$dataType = \OxidEsales\Eshop\Core\Field::T_RAW;
}
}

return parent::_setFieldData($sFieldName, $sValue, $iDataType);
return parent::_setFieldData($fieldName, $value, $dataType);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion source/Application/Model/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ public function getStdLink($iLang = null, $aParams = [])
*/
protected function _setFieldData($sFieldName, $sValue, $iDataType = \OxidEsales\Eshop\Core\Field::T_TEXT)
{
if ('oxcontent' === strtolower($sFieldName) || 'oxcontents__oxcontent' === strtolower($sFieldName)) {
$sLoweredFieldName = strtolower($sFieldName);
if ('oxcontent' === $sLoweredFieldName || 'oxcontents__oxcontent' === $sLoweredFieldName) {
$iDataType = \OxidEsales\Eshop\Core\Field::T_RAW;
}

Expand Down
14 changes: 9 additions & 5 deletions source/Core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1068,13 +1068,17 @@ public function getShopCurrency()
*/
public function getActShopCurrencyObject()
{
$cur = $this->getShopCurrency();
$currencies = $this->getCurrencyArray();
if (!isset($currencies[$cur])) {
return $this->_oActCurrencyObject = reset($currencies); // reset() returns the first element
if ($this->_oActCurrencyObject === null) {
$cur = $this->getShopCurrency();
$currencies = $this->getCurrencyArray();
if (!isset($currencies[$cur])) {
$this->_oActCurrencyObject = reset($currencies); // reset() returns the first element
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the coding standards. "_" and "hungarian" notations are not allowed in new code anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property already exists, renaming it because of a change of indentation would be too much for the addition of an "if" I think. Are you sure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaxBoeh, you are right, sorry, haven't noticed. I thought it is some new one for caching. Thanks for clarifying.

} else {
$this->_oActCurrencyObject = $currencies[$cur];
}
}

return $this->_oActCurrencyObject = $currencies[$cur];
return $this->_oActCurrencyObject;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions source/Core/Model/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,7 @@ public function assign($dbRecord)
return;
}

reset($dbRecord);
while (list($name, $value) = each($dbRecord)) {
foreach ($dbRecord as $name => $value) {
$this->_setFieldData($name, $value);
}

Expand Down Expand Up @@ -1235,15 +1234,16 @@ protected function _setFieldData($fieldName, $fieldValue, $dataType = Field::T_T
}
}
// if we have a double field we replace "," with "." in case somebody enters it in european format
if ($this->isPropertyLoaded($longFieldName)
$isPropertyLoaded = $this->isPropertyLoaded($longFieldName);
if ($isPropertyLoaded
&& isset($this->$longFieldName->fldtype)
&& $this->$longFieldName->fldtype == 'double'
) {
$fieldValue = str_replace(',', '.', $fieldValue);
}

// isset is REQUIRED here not to use getter
if ($this->isPropertyLoaded($longFieldName)
if ($isPropertyLoaded
&& is_object($this->$longFieldName)
) {
$this->$longFieldName->setValue($fieldValue, $dataType);
Expand Down