Forums / Developer / Can $attribute->store() be replaced by $object->store()

Can $attribute->store() be replaced by $object->store()

Author Message

Eirik Alfstad Johansen

Monday 06 June 2005 6:17:40 am

Hi,

I've written an a script which imports and updates objects, but it runs really slow so I'm taking a look at what I can do to optimize it.

Browsing my code, I noticed that I do the following for each attribute:

$objectAttributes[$i]->setAttribute( 'data_text', $data );
$objectAttributes[$i]->store();

And then the following at the end:

$object->store();

So, my question is whether or not I need to call the store method for each attribute, or whether the calling it for the object at the end is sufficient.

Thanks in advance !

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Kristian Hole

Monday 06 June 2005 7:41:03 am

The short answer to your post: yes.

The long answer: The attributes and objects are stored in different tables in the database, so you need to store them individually

:)

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Eirik Alfstad Johansen

Monday 06 June 2005 10:01:08 am

Hi Kristian,

Thanks for the heads up. I was thinking that maybe the object method looped through the attributes and stored them as well, but I guess that's not the case.

I must say, I find it confusing to create, or in this case modify, ezp objects in PHP, making me think that I might be using uneccessary code. Here's a short hand version of what I do. Are there any commands that could be dropped?

// fetch object
$object = eZContentObject::fetch($objectID);

// not sure if this fetches the current version or creates a new version
$version =& $object->version( $object->attribute('current_version') );

// set version status to draft
$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
$version->store();

// update object name
$object->setAttribute( 'name', $name);

// fetch object attributes
$objectAttributes =& $version->contentObjectAttributes();

// update and store attribute
$objectAttributes[0]->setAttribute( 'data_int', $data_int );
$objectAttributes[0]->store();

// store object
$object->store();

// publish the new/current/whatever version
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $object->attribute( 'id' ), 'version' => $object->attribute('current_version') ) );

Running this code takes about 0.2 seconds (I update a few more attributes) and when the objects are in the hundreds, the execution time really starts to drag out.

I would have no problem modifying the existing current version instead of creating a new one if it would save me some time.

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Eirik Alfstad Johansen

Thursday 09 June 2005 3:18:11 am

Please, guys? I'm assuming this would be easy to answer for an eZP employee.

Thanks in advance !

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Tom Couwberghs

Thursday 09 June 2005 7:33:26 am

Hi Erik,

you can just change the current version (if this is what your looking for) and forget about republishing the object.

It is the publish trigger that takes so long, because it sends the object trough a range of actions (checking workflow, re-indexing, ...)

hope this helps

Tom

Eirik Alfstad Johansen

Thursday 09 June 2005 10:04:18 am

Hi Tom,

Thanks a lot for helping me out. Here's what I tried following your suggestion.

1. Removed the publish code: Object content is not updated unless I enter edit mode and publish it from there. Also complains about unpublished draft.

2. Removed the publish code and code which I (assume) creates a new draft (at the top): Same as above, but no complaining about unpublished draft.

3. Kept publishing code, and removed the creation of a new version: This seems to work, but it isn't saving me a lot of time (a measly 0.02 seconds pr entry).

Am I missing something here, or was this your suggestion?

Thanks in advance !

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Tom Couwberghs

Thursday 09 June 2005 11:34:09 pm

Hi Erik,

just do the following:

$object = eZContentObject::fetch($objectID);

// update object name
$object->setAttribute( 'name', $name);
$object->store();

// fetch object attributes
$objectData = &$object->dataMap();

$attr = &$objectData['name_of_your_attrib'];

$attr->setAttribute( 'data_int', 5 );
$attr->store();

I haven't tested this code, so beware of typo's.

--T

eZ debug

Timing: Jan 18 2025 18:38:27
Script start
Timing: Jan 18 2025 18:38:27
Module start 'content'
Timing: Jan 18 2025 18:38:28
Module end 'content'
Timing: Jan 18 2025 18:38:28
Script end

Main resources:

Total runtime0.8144 sec
Peak memory usage4,096.0000 KB
Database Queries208

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0085 587.8438180.8125
Module start 'content' 0.00850.6702 768.6563643.4531
Module end 'content' 0.67870.1356 1,412.1094345.0547
Script end 0.8143  1,757.1641 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00410.5075210.0002
Check MTime0.00150.1869210.0001
Mysql Total
Database connection0.00110.131410.0011
Mysqli_queries0.724288.93432080.0035
Looping result0.00220.27462060.0000
Template Total0.780295.820.3901
Template load0.00200.247120.0010
Template processing0.778295.562420.3891
Template load and register function0.00010.014710.0001
states
state_id_array0.00110.135810.0011
state_identifier_array0.00110.141120.0006
Override
Cache load0.00180.2159520.0000
Sytem overhead
Fetch class attribute can translate value0.00140.174140.0004
Fetch class attribute name0.00130.1580100.0001
XML
Image XML parsing0.00180.217640.0004
class_abstraction
Instantiating content class attribute0.00000.0052140.0000
General
dbfile0.00200.2493390.0001
String conversion0.00000.000730.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
7content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 31
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs