Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ericduran’s picture

Status: Active » Reviewed & tested by the community
FileSize
606 bytes

:)

dddave’s picture

Status: Reviewed & tested by the community » Needs review

correcting status

ericduran’s picture

@dddave lol I did that on purpose.

Dave Reid’s picture

Arrays of objects don't usually need to be passed by reference, because the objects inside the arrays are references by default as of PHP 5. Can someone explain why this is needed?

Dave Reid’s picture

Would actual alter hooks on both entityCacheGet and entityCacheSet() help here? Implementing hook_entitycache_node_load_alter() would be a more proper place to *unset* an entity from the array, rather than using hook_entitycache_node_load().

ericduran’s picture

Yes yes, that actually makes more sense.

I'll test this patch and get back to this issue.

Elijah Lynn’s picture

Title: entityCacheAttachLoad doesn't take the param by References » entityCacheAttachLoad doesn't take the $enitites param by reference
ericduran’s picture

Status: Needs review » Reviewed & tested by the community

This is good. Title could probably be change but it does solve my issue.

catch’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Closed (works as designed)

This is by design. You shouldn't be able to mess with the actual list of entities here. And it's the same for hook_node_load().

Dave Reid’s picture

Status: Closed (works as designed) » Needs review

I disagree and think this is still worth considering.

And it's the same for hook_node_load().

I don't understand what this is supposed to mean.

ericduran’s picture

@catch I think the confusion is with the title.

This title should probably be changed to add drupal_alter() to entityCacheSet & entityCacheGet.

Elijah Lynn’s picture

Title: entityCacheAttachLoad doesn't take the $enitites param by reference » Add drupal_alter() to entityCacheSet & entityCacheGet
Elijah Lynn’s picture

I updated a minor typo.

catch’s picture

No-one's explained why you need to be able to remove items from the array of entities.

ericduran’s picture

@catch Sorry I thought I did but in retrospect it was in a conversation on IRC.

In short the conflict is integration with with https://drupal.org/project/sps and Entity Cache.

Highly level the way sps works during preview is it says if you need to show NID 5 replace that NID with NID 5 but the revision 7 allowing people to essentially preview a node that might be schedule for a week from now.

This works great until EntityCache is thrown in the mix. Mainly because when EntityCache is enable and you request NID 5 it says great, I already have this and just return the previous loaded node, not giving SPS a chance to alter the value.

What we do in our implementation is we tell entity cache to skip all cache objects when a user is in Preview mode. This isn't that big of a deal for us performance wise since the cache objects are still available for regular request except they get skipped once someone starts Previewing the site (Which is very few people for a very short time).

Is this helpful?

ericduran’s picture

Besides the explanation above I can think of a couple of other usages:
- I want entity foo to always skip cache
- I want entity bar to only cache within certain conditions

^^ Not real usages of mine but still valid-ish.

catch’s picture

Can't SPS implement hook_entity_load_uncached() and do the replacement in there?

anbarasan.r’s picture

Version: 7.x-1.x-dev » 7.x-1.5
FileSize
1.49 KB

Re rolling the patch against 7.x-1.5.

Status: Needs review » Needs work

The last submitted patch, 18: 2044291-proper-alter-hooks-18.patch, failed testing.

The last submitted patch, 18: 2044291-proper-alter-hooks-18.patch, failed testing.

anbarasan.r’s picture

Status: Needs work » Needs review
FileSize
1.27 KB

Re rolling the patch against 7.x-1.5. Updated the file path.

ericduran’s picture

I'm extremely late to this issue.

To answer @catch last question. I don't remember if I tested with hook_entity_load_uncached. Looking at it now it might seem possible to replace the entire entity object in there.

I'm no longer in need of this so I'll leave that for other folks. That being said if it is possible I guess this can be mark as works as designed.

DamienMcKenna’s picture

Version: 7.x-1.5 » 7.x-1.x-dev
Category: Bug report » Feature request
Status: Needs review » Needs work

This needs documentation in entitycache.api.php. This is also a feature request, not a bug.

czigor’s picture

Status: Needs work » Needs review
FileSize
2.29 KB
  1. +++ b/includes/entitycache.entitycachecontrollerhelper.inc
    @@ -227,12 +227,21 @@ class EntityCacheControllerHelper extends DrupalDefaultEntityController {
    +        drupal_alter(array('entitycache_load', 'entitycache_' . $controller->entityType . '_load'), $cached_entities);
    

    Just before this in the self::entityCacheAttachLoad($controller, $cached_entities); call we already have a chance to alter entities one by one with hook_entitycache_load(). So not sure when this is necessary but if it is, let's throw hook_entitycache_load() out.

  2. +++ b/includes/entitycache.entitycachecontrollerhelper.inc
    @@ -227,12 +227,21 @@ class EntityCacheControllerHelper extends DrupalDefaultEntityController {
    +    drupal_alter(array('entitycache_save', 'entitycache_' . $controller->entityType . '_save'), $entities);
    

    I would call this hook_entitycache_set_alter() since we usually say 'setting' the cache instead of 'saving' it.

The attached patch addresses the above issues and also creates a hook_entitycache_postset_alter() to alter the entities after saving them to the cache. My use case is #2768857: Overwritten titles when using entitycache, panelizer and entity_translation modules.

czigor’s picture

An entity type argument was missing from drupal_alter().

Fabianx’s picture

Title: Add drupal_alter() to entityCacheSet & entityCacheGet » Add drupal_alter() to entityCacheGet & entityCacheSet & resetEntityCache
Category: Feature request » Task
Priority: Normal » Major
FileSize
3.27 KB

Thanks for all the work on this, I needed this too but already worked on it before seeing this issue.

So I am sorry for posting yet another patch, but I am sure we can combine (and also get a quick commit).

--

I am not seeing why we need postset right now, but I added some more to deal with clearing caches, which is very useful.

Also the alter should be before retrieving from cache (I am implementing this for CPS, a module like SPS).

If I can see why postset is needed, I'll add it later.

Fabianx’s picture

Okay, I get the use case, I added it to my patch, so we can get quick RTBC and commit.

  • catch committed f82940e on 7.x-1.x
    Issue #2044291 by czigor, anbarasan.r, Fabianx, ericduran, Elijah Lynn,...
catch’s picture

Status: Needs review » Fixed

Committed/pushed to 7.x-1.x, thanks!

Had a couple of ropey releases with entitycache, so will leave this in dev for a little while.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.