Forums / Developer / publish objects from script without cache clear

publish objects from script without cache clear

Author Message

Marko Žmak

Wednesday 05 January 2011 4:34:00 am

I'd like to create and publish an object from a PHP script but without clearing the cache.

What's the best way to do it?

P.S. I tried using the "content, publish" operation via eZOperationHandler::execute(), but it always clears the cache and it seems like there's no way to avoid it.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Nicolas Pastorino

Wednesday 05 January 2011 6:13:12 am

Hi Marko !

The brute-force approach would be to duplicate the $OperationList['publish'] operation (from kernel/content/operation_definition.php) in a custom module, and comment out the part related to cache clearing :

array( 'type' => 'method',
                                                           'name' => 'clear-object-view-cache',
                                                           'frequency' => 'once',
                                                           'method' => 'clearObjectViewCache',
                                                           'parameters' => array(  array( 'name' => 'object_id',
                                                                                          'type' => 'integer',
                                                                                          'required' => true ),
                                                                                   array( 'name' => 'version',
                                                                                          'type' => 'integer',
                                                                                          'required' => true ) ) ),
                                                    // PreGeneration: This generates view cache for a given set of users if enabled
                                                    array( 'type' => 'method',
                                                           'name' => 'generate-object-view-cache',
                                                           'frequency' => 'once',
                                                           'method' => 'generateObjectViewCache',
                                                           'parameters' => array(  array( 'name' => 'object_id',
                                                                                          'type' => 'integer',
                                                                                          'required' => true ) ) ),

You can then call your module's custom 'publish' operation from PHP.

I must confess i never tried this myself, so i'll be glad to hear about your experiment :)

Cheers !

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

gilles guirand

Wednesday 05 January 2011 8:19:17 am

You could also play with the setVariable (eZINI) method to temporary unset some ini (like the smart view cache)

@Nicolas : I found today another method in Kaliop's code (@g4vroche copyright)

private function disablePublishOperation( $index )
    {
        if( !isset( $GLOBALS['eZGlobalModuleOperationList']['content'] ) )
        {
            $moduleOperationInfo = new eZModuleOperationInfo( 'content', false );
            $moduleOperationInfo->loadDefinition();

            $GLOBALS['eZGlobalModuleOperationList']['content'] = $moduleOperationInfo;
        }

        unset(  $GLOBALS['eZGlobalModuleOperationList']['content']->OperationList['publish']['body'][$index] );

    }

So, to disable cache cleaning :

self::disablePublishOperation( 13 );
 self::disablePublishOperation( 14 );

--
Gilles Guirand
eZ Community Board Member
http://twitter.com/gandbox
http://www.gandbox.fr

Bertrand Dunogier

Wednesday 05 January 2011 8:40:56 am

As far as I remember, cache won't be cleared if ViewCache is disabled.

eZINI::instance()->setVariable( 'ContentSettings', 'ViewCaching', 'disabled' );

Try this before running the import.

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Nicolas Pastorino

Wednesday 05 January 2011 8:51:03 am

"

@Nicolas : I found today another method in Kaliop's code (@g4vroche copyright)

private function disablePublishOperation( $index )
    {
        if( !isset( $GLOBALS['eZGlobalModuleOperationList']['content'] ) )
        {
            $moduleOperationInfo = new eZModuleOperationInfo( 'content', false );
            $moduleOperationInfo->loadDefinition();

            $GLOBALS['eZGlobalModuleOperationList']['content'] = $moduleOperationInfo;
        }

        unset(  $GLOBALS['eZGlobalModuleOperationList']['content']->OperationList['publish']['body'][$index] );

    }

So, to disable cache cleaning :

self::disablePublishOperation( 13 );
 self::disablePublishOperation( 14 );
"

Nifty trick, well done @g4vroche

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Marko Žmak

Wednesday 05 January 2011 9:15:10 am

@gilles: It's a really nice trick, but I'm looking for a more "clean" way. Because if the order of operations for "content,publish" changes this trick won't work unless you change the index in the disablePublishOperation() call

@Bertrand: This looks like the right way to do it. But shouldn't I also disable the TemplateCache in order to disable clearing of template cache blocks? Are there any other settings that should be disabled in order to fully disable the cache clearing?

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Marko Žmak

Thursday 06 January 2011 12:48:38 pm

OK, after further investigation I came to this conclusions...

The solution Bertrand suggested should be extended to disable other caching mechanisms, so it should be like this:

eZINI::instance()->setVariable( 'ContentSettings', 'ViewCaching', 'disabled' );
eZINI::instance()->setVariable( 'ContentSettings', 'StaticCache', 'disabled' );
eZINI::instance()->setVariable( 'ContentSettings', 'PreViewCache', 'disabled' );

The solution gilles suggested can be enhanced a little bit by finding the array value to unset via its name. When set this way works even better that disabling the cache via ini settings.

So I made a better function:

function disableModuleOperation( $moduleName, $operationName, $operationPartName )
{
        if( !isset( $GLOBALS['eZGlobalModuleOperationList'][$moduleName] ) )
        {
                $moduleOperationInfo = new eZModuleOperationInfo( $moduleName, false );
                $moduleOperationInfo->loadDefinition();

                $GLOBALS['eZGlobalModuleOperationList'][$moduleName] = $moduleOperationInfo;
        }

        if (!isset($GLOBALS['eZGlobalModuleOperationList'][$moduleName]->OperationList[$operationName]))
                return;

        $index = -1;

        foreach ($GLOBALS['eZGlobalModuleOperationList'][$moduleName]->OperationList[$operationName]['body'] as $key => $operationPart)
        {
                if ($operationPart['name'] == $operationPartName)
                {
                        $index = $key;
                        break;
                }
        }

        if ($index >= 0)
                unset( $GLOBALS['eZGlobalModuleOperationList'][$moduleName]->OperationList[$operationName]['body'][$index] );
}

which would then be used like this:

disableModuleOperation('content', 'publish', 'clear-object-view-cache');

This is a more safer way to unset a part of the module operation because it relies on the name of the part which is less likely to change than the index.

I also found that there are several other parts that can be excluded when importing objects in a script:

  • pre_publish - if you don't want pre publish triggers to be executed
  • post_publish - if you don't want post publish triggers to be executedh
  • generate-object-view-cache - no preview cache generation
  • create-notification - if you don't want to generate notifications for the imported objects
  • register-search-object - to disable the search indexing (the reindexing can be done after the import)

Furthermore, I found that disabling "register-search-object" gives you the biggest speedup, especially if you're using ezfind. In my case the import went 100 times faster (without exaggeration). And you can always do the complete reindexing after the import.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Bertrand Dunogier

Friday 07 January 2011 3:00:34 am

The stuff in this thread is really cool !

Being able to disable parts of an operation is actually one of our plans for the Asynchronous publishing feature. The goal is partially implement the ezpContentPublishingStategy concept introduced when presenting the future PHP API skeletons. The default strategy would run everything, while custom strategies could be created, and set as the default one in order to skip some operation methods.

Chances are big that i'll work on that today, I'll let you know.

Also note that Asynchronous publishing should make import MUCH faster as well... the content/publish operation executed in the script will be asynchronous, and will be actually executed by the daemon. If you don't need your items details (you can still use the content object ids, etc, but the object might not be published), it should make imports much faster.

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Marko Žmak

Tuesday 31 May 2011 1:57:37 am

"

The stuff in this thread is really cool !

Being able to disable parts of an operation is actually one of our plans for the Asynchronous publishing feature. The goal is partially implement the ezpContentPublishingStategy concept introduced when presenting the future PHP API skeletons. The default strategy would run everything, while custom strategies could be created, and set as the default one in order to skip some operation methods.

"

Now that the async publishing feature is out, could you shed some light about this one?

Do we have the way to disable parts of publish operation?

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

eZ debug

Timing: Jan 17 2025 23:52:31
Script start
Timing: Jan 17 2025 23:52:31
Module start 'content'
Timing: Jan 17 2025 23:52:32
Module end 'content'
Timing: Jan 17 2025 23:52:32
Script end

Main resources:

Total runtime1.0785 sec
Peak memory usage4,096.0000 KB
Database Queries219

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0082 588.9766180.8203
Module start 'content' 0.00820.9508 769.7969765.4297
Module end 'content' 0.95900.1195 1,535.2266352.4297
Script end 1.0784  1,887.6563 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00420.3872210.0002
Check MTime0.00150.1405210.0001
Mysql Total
Database connection0.00130.120310.0013
Mysqli_queries0.974790.37272190.0045
Looping result0.00230.20932170.0000
Template Total1.050097.420.5250
Template load0.00210.193920.0010
Template processing1.047997.155820.5239
Template load and register function0.00010.010910.0001
states
state_id_array0.00100.088610.0010
state_identifier_array0.00090.082720.0004
Override
Cache load0.00200.1818810.0000
Sytem overhead
Fetch class attribute can translate value0.00150.140750.0003
Fetch class attribute name0.00140.1328130.0001
XML
Image XML parsing0.00250.228250.0005
class_abstraction
Instantiating content class attribute0.00000.0034180.0000
General
dbfile0.00230.2129480.0000
String conversion0.00000.000630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
9content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
9content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
22content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
9content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
7content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
2content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
3content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
5content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
1content/datatype/view/ezxmltags/ul.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ul.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 69
 Number of unique templates used: 11

Time used to render debug report: 0.0002 secs