Forums / General / Add to bookmarks and viewcache

Add to bookmarks and viewcache

Author Message

Carlos Revillo

Tuesday 11 November 2008 12:49:52 pm

Hi.

We're working in a community site and we want "add to bookmark" links in every content.

let's suppose we have articles and registered users could add this article (node) to their favourite links off the site.

We have built a small extension for adding and removing from bookmarks. This extension uses

eZContentBrowseBookmark::createNew($userID,$nodeID,$nodeName);

for adding and

$bookmark=eZContentBrowseBookmark::fetch($bookmarkID);
$bookmark->remove();

for deleting.

Ideally, when user use add to favourite link, bookmark should be added and the user will be redirected to the same article

As user has added the node to bookmarks, the "add to bookmark" link needs to be changed by a "remove from bookmarks" link.

But i don't really know if this is possible having viewcache enabled and not having

{set-block scope=root variable=cache_ttl}0{/set-block}

in the very top of the template.

I mean. I would like to cache everything in the node/view/full/article.tpl template except the part for those add and remove from bookmarks link.

Any ideas? Thank you.

André R.

Tuesday 11 November 2008 1:13:45 pm

Alt 1:
You need pr user cache on those pages then, supported in 4.1, look here:
http://issues.ez.no/IssueView.php?Id=13274&activeItem=1
And clear cache with:
eZContentCache::cleanup( array( $nodeID ), $userID );

Alt 2:
Store node id's in cookie and show / hide the button based on that compared to current node id of the page.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Carlos Revillo

Tuesday 11 November 2008 2:49:41 pm

Thanks for the reply.

Site is online now. It's eZ 4.0.0. customer probably wants to migrate to 4.0.1. Is there any chance to apply your patch to a eZ 4.0.0 installation?

For second alternative i don't really follow you. we'll need to query this cookie for that, but, if viewcache is enabled, the response will be always the same, won't?

Carlos Revillo

Sunday 16 November 2008 10:17:21 am

Hi again Andre.

I have tried the patch and it works perfectly.
But it only works for a node. What we need is something similar for every object of a class.

Suppose you have an "article" class. it would be nice to add something to tell ez to generate cache files for every node of this class and not only for a node.

This way, when you add a new article and you want to add an "add to favourites" link you need to add an entry for

ViewCacheSettings[newNodeIDhere]=pr_user

I think it would be nice to add something like

ViewCacheSettingsByClass[30]=pr_user

or something like this. Do you think this is possible? I'll try myself and let you know if you want...

André R.

Sunday 16 November 2008 1:12:11 pm

Do you think this is possible?

It's possible but the node is not fetched yet at this point so it is not something I'll consider.
So you might want to rethink how you implement this, does the bookmark code really need to be in the node template instead of in the pagelayout?
Or you can implement it with some javascript in pagelayout to show / hide the add to bookmarks stuff, there you can use cache-blocks where you have higher flexibility on how you cache stuff.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Carlos Revillo

Sunday 16 November 2008 2:09:10 pm

At the point of the development it would be more difficult to pass the add to bookmars stuff than adding a cache_ttl to 0 for example.

I prefer not considering javascript option because accesibility (WAI) reasons.
Also, working with cache-blocks in this template, will me make to set a node_id as a expiry key... and i've told to use cache-blocks expiry keys as unique as possible. lot of cache-blocks could overhead the system.

My idea is to fetch node and get this class, so i was thinking about adding some code in kernel/content/view.php.

Getting your code from the svn at revision 25222, it would be something like

 $viewCacheSettings = $ini->variable( 'ContentSettings', 'ViewCacheSettings' );
    if ( isset( $viewCacheSettings[$NodeID] ) )
    {
        $viewCacheSetting = $viewCacheSettings[$NodeID];
        if ( $viewCacheSetting === 'disabled' )
        {
            $viewCacheEnabled = false;
        }
    }
	else
	{
		$viewCacheSettingsClass = $ini->variable( 'ContentSettings', 'ViewCacheSettingsClass' );
		$node = eZContentObjectTreeNode::fetch($NodeID);
		if ( isset( $viewCacheSettingsClass[$node->classIdentifier()] ) )
	    {
	        $viewCacheSetting = $viewCacheSettingsClass[$node->classIdentifier()];
	        if ( $viewCacheSetting === 'disabled' )
	        {
	            $viewCacheEnabled = false;
	        }
	    }
	}

and i would add another config variable in site.ini. My site.ini.append.php would probably looks like

[ContentSettings]
ViewCacheSettingsClass[article]=pr_user

Works in my tests, but i also think this is a "hack" to kernel/content/view.php that i would prefer not having to do :).

eZ debug

Timing: Jan 18 2025 18:16:12
Script start
Timing: Jan 18 2025 18:16:12
Module start 'content'
Timing: Jan 18 2025 18:16:12
Module end 'content'
Timing: Jan 18 2025 18:16:12
Script end

Main resources:

Total runtime0.8945 sec
Peak memory usage4,096.0000 KB
Database Queries203

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0068 587.7031180.8438
Module start 'content' 0.00690.7498 768.5469596.3125
Module end 'content' 0.75670.1378 1,364.8594341.3828
Script end 0.8945  1,706.2422 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00430.4772210.0002
Check MTime0.00150.1721210.0001
Mysql Total
Database connection0.00110.127910.0011
Mysqli_queries0.804789.95192030.0040
Looping result0.00200.21942010.0000
Template Total0.860096.120.4300
Template load0.00200.226720.0010
Template processing0.858095.912020.4290
Template load and register function0.00010.015810.0001
states
state_id_array0.00130.147410.0013
state_identifier_array0.00150.164420.0007
Override
Cache load0.00170.1932570.0000
Sytem overhead
Fetch class attribute can translate value0.00140.154130.0005
Fetch class attribute name0.00210.238770.0003
XML
Image XML parsing0.00090.099730.0003
class_abstraction
Instantiating content class attribute0.00000.002080.0000
General
dbfile0.00330.3651280.0001
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
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
16content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
8content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 39
 Number of unique templates used: 7

Time used to render debug report: 0.0005 secs