View Issue Details

IDProjectCategoryView StatusLast Update
0006677OXID eShop (all versions)1.04. Content, static (register, contact etc.) pagespublic2023-11-15 15:24
Reportertimwetter Assigned To 
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionfixed 
Product Version4.9.10 / 5.2.10 
Summary0006677: oxcontent: full content loaded from db, but only title and link required for menu
Descriptionfull oxcontent object is loaded for building menu,
but content is not required, but loaded

when the system loads the menu:
here espacially the static cms links and title the full oxcontent object gets loaded via smarty [{oxifcontent ident="oxagb" object="oCont"}], but
the system do not require the oxcontent__content(_[0-9]+)*

at this point only title and link is required to build the link and name it for the user.

solution: do not load content from db when its not required for any purpose


Additional Informationmy solution - a little dirty:

##############################################################################
block.oxifcontent.php:
function smarty_block_oxifcontent( $params, $content, &$smarty, &$repeat)
{
    $myConfig = oxConfig::getInstance();

    $sIdent = isset( $params['ident'] )?$params['ident']:null;
    $sOxid = isset( $params['oxid'] )?$params['oxid']:null;
    $sAssign = isset( $params['assign'])?$params['assign']:null;
    $sObject = isset( $params['object'])?$params['object']:'oCont';
    $bLoadContent = isset( $params['loadcontent'])?$params['loadcontent']:true;

    if ($repeat) {
        if ( $sIdent || $sOxid ) {

            static $aContentCache = array();

            if ( ( $sIdent && isset( $aContentCache[$sIdent] ) ) ||
                ( $sOxid && isset( $aContentCache[$sOxid] ) ) ) {
                $oContent = $sOxid ? $aContentCache[$sOxid] : $aContentCache[$sIdent];
            } else {
                $oContent = oxNew( "oxContent" );
                $blLoaded = $sOxid ? $oContent->load( $sOxid ) : ( $oContent->loadbyIdent( $sIdent, $bLoadContent ) );
                if ( $blLoaded && $oContent->isActive() ) {
                    $aContentCache[$oContent->getId()] = $aContentCache[$oContent->getLoadId()] = $oContent;
                } else {
                    $oContent = false;
                    if ( $sOxid ) {
                        $aContentCache[$sOxid] = $oContent;
                    } else {
                        $aContentCache[$sIdent] = $oContent;
                    }
                }
            }

            $blLoaded = false;
            if ( $oContent ) {
                $smarty->assign($sObject, $oContent);
                $blLoaded = true;
            }
        } else {
            $blLoaded = false;
        }
        $repeat = $blLoaded;
    } else {
        $oStr = getStr();
        $blHasSmarty = $oStr->strstr( $content, '[{' );
        if ( $blHasSmarty ) {
            $content = oxUtilsView::getInstance()->parseThroughSmarty( $content, $sIdent.md5($content), $myConfig->getActiveView() );
        }

        if ($sAssign) {
            $smarty->assign($sAssign, $content);
        } else {
            return $content;
        }
    }


}


#############################################################################
oxcontent

    public function loadByIdent( $sLoadId, $bLoadContent = true )
    {
        $sSelect = $this->buildSelectString( array( 'oxcontents.oxloadid' => $sLoadId,
            'oxcontents.'.$this->getSqlFieldName( 'oxactive' ) => '1',
            'oxcontents.oxshopid' => $this->getConfig()->getShopId() ) );


        if (!$bLoadContent) {
            $sSelect = str_replace('oxcontents.oxcontent_1 as oxcontent,', "'' as oxcontent,", $sSelect);
            $sSelect = str_replace('oxcontents.oxcontent as oxcontent,', "'' as oxcontent,", $sSelect);
        }

        $blRet = false;

        $oDB = oxDb::getDb(true);

        $rs = $oDB->CacheExecute(900, $sSelect);
        if ($rs != false && $rs->recordCount() > 0) {
            $blRet = true;
            $this->assign( $rs->fields);
        }

        return $blRet;

    }

##################################################################
usage (in tpl):
[{oxifcontent ident="oxagb" object="oCont" loadcontent=false}]
TagsCMS, Smarty
ThemeAll
BrowserAll
PHP VersionAll
Database VersionAll

Activities

SvenBrunk

2023-11-15 15:24

administrator   ~0015741

1) Smarty is no longer supported
2) I think the solution is not really helpful. If ifcontent assigns an object ( object="oCont" ) then the object should be available.

It should be possible though to detect content availability without loading the full object though and loading content should be lazy. In OXID 7 this is the case and the result is also cached.