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 2 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
11 changes: 9 additions & 2 deletions source/Application/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,15 @@ protected function _update()
protected function _setFieldData($sFieldName, $sValue, $iDataType = \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)) {
if (($sFieldNameIndex2 = $sFieldName[2]) === 'l'
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use hungarian notations anymore. Check our coding styles agreements.

Copy link
Member

Choose a reason for hiding this comment

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

Please don't make complex conditions even more complex :) Try to improve the readability instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hungarian: I know, but wanted to keep the method in a consistent style. I changed it :)

Without the assignment within the condition we either need to assign the character before (including isset) or duplicate the conditioned code. I think both options are worse than the maybe-saving of an access of the 16 index, I reverted most of the condition

|| $sFieldNameIndex2 === 'L'
|| (isset($sFieldName[16])
&& (($sFieldNameIndex16 = $sFieldName[16]) === 'l'
|| $sFieldNameIndex16 === 'L')
)
) {
$sLoweredFieldName = strtolower($sFieldName);
if ('oxlongdesc' === $sLoweredFieldName || 'oxcategories__oxlongdesc' === $sLoweredFieldName) {
$iDataType = \OxidEsales\Eshop\Core\Field::T_RAW;
}
}
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