Problem/Motivation

When passing a (non empty) array of $options to scald_render(), that part of the cache id is going to be 'Array' regardless of the contents of the array.
Imagine rendering the same scald image with different image styles, that'll cause to always show the first rendered scald image to be shown, ignoring the different images styles of the following render requests.

Proposed resolution

Hash the options.

Remaining tasks

Test coverage?

User interface changes

None.

API changes

None.

Data model changes

Corrected cache ids.

Comments

PieterDC created an issue. See original summary.

pieterdc’s picture

Assigned: pieterdc » Unassigned
Status: Active » Needs review
StatusFileSize
new534 bytes

Patch attached, unassigning myself and putting to 'Needs review'.

Status: Needs review » Needs work

The last submitted patch, 2: fix_scald_render_cache-2570191-2.patch, failed testing.

pieterdc’s picture

Version: 7.x-1.4 » 7.x-1.x-dev
Priority: Major » Normal
Status: Needs work » Needs review
StatusFileSize
new534 bytes

Automated tests failed in places I didn't touch.
Rerolled the patch against 7.x-1.x, which had to be done anyway.
Let's see how it goes now.

nagy.balint’s picture

Hi, thanks for the patch!

I think we should also check if its a string or not after checking if its an array, so if its a string we can md5 there as well, and if its not a string then we would add the value unaltered. Though most of the cases it will be a string i think.

So something like

    if (is_array($options)) {
      $cache_parts[] = md5(drupal_json_encode($options));
    }
    else if (is_string($options)) {
      $cache_parts[] = md5($options);
    }
    else {
      $cache_parts[] = $options;
    }

So then in case of giving a string value, it will always have md5 result at the end.

nagy.balint’s picture

Status: Needs review » Needs work

because of comment #5

nagy.balint’s picture

Actually there are bigger problems here, since if I give it an array like
scald_render(200,'sdl_editor_representation', array('link' => 'test'));

Then it will give me an error:
Warning: json_decode() expects parameter 1 to be string, array given in drupal_json_decode() (line 5111 of includes/common.inc).

So the problem is that if its an array then the following line fails:

  // If $options is not a JSON string or a single value, give other modules a
  // chance to handle it.
  if ($options) {
    if (!is_array($decoded = drupal_json_decode($options))) {

So maybe the best is to always convert to json if its an array at the very beginning of the render function.

@jcisio what do you think?

gifad’s picture

Status: Needs work » Needs review
StatusFileSize
new985 bytes

Fix for #7

nagy.balint’s picture

Status: Needs review » Needs work

Thanks, but it does not include 5

gifad’s picture

#8 does not include the fix you suggested in #5, but it does fix the issue you mentioned.
It just skips the useless decode step of an array $options, which is passed unchanged to following steps.
At least it works for me; did you try it ?

nagy.balint’s picture

No it does not fix it...

As you can see the string is md5 coded in the patch... now if you just input a json encoded string, then it wont be md5 coded, and therefore two identical options array will be considered as different.

nagy.balint’s picture

Status: Needs work » Needs review
StatusFileSize
new1.04 KB

So something like this.

  • nagy.balint committed deaab3a on 7.x-1.x
    Issue #2570191 by PieterDC, nagy.balint, gifad: Fix Scald render cache...
nagy.balint’s picture

Status: Needs review » Fixed

Thanks, Committed.

Status: Fixed » Closed (fixed)

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