If an profile, which has an image, is updatet, imagecache flushes all presets,
even when the image has not changed.

if ($op == 'update' && !empty($account->picture)) {
   imagecache_image_flush($account->picture);
}

To reduce server load, I think it would be better to check if the image has changed.

if($op == 'update') {
   //Only flush when the picture ist realy new, or deleted
   if($edit['picture'] OR $edit['picture_delete'] == 1) {
    imagecache_image_flush($account->picture);
}    
  }

Nicolas.

Comments

drewish’s picture

Category: feature » task

please roll a patch.

hankpalan.com’s picture

Is the imagecache flushing the profile pic already and its just a matter of how to do it properly?

I ask this because if I upload a new profile image it doesn't display until I refresh the page. Am I doing something wrong or is that what this issue is about?

drewish’s picture

hankpalan.com, that's actually a core bug as well. since the image goes into the same place the browser assumes it's the same file.

drewish’s picture

Status: Active » Needs work
tantenic’s picture

I've tested the following solution:

in user.module.php on line 426 I have added a timestamp to the destination behind $form['#uid'].
Now, the filename changes on every upload and the browser does not asume the same file.

    // The image was saved using file_save_upload() and was added to the
    // files table as a temporary file. We'll make a copy and let the garbage
    // collector delete the original upload.
    $info = image_get_info($file->filepath);
    $destination = variable_get('user_picture_path', 'pictures') .'/picture-'. $form['#uid'] .'-'.time().'.'. $info['extension'];

It works on my local testsite.

drewish’s picture

I think a better solution might be to just stick the timestamp in the query portion of the link to the image displayed on the edit form. You could probably do that with a form alter rather than hacking core.

tantenic’s picture

OK, how about this:

If the image is a user-image, the timestamp of the last modification is added to the url.
Now it is no core hack, but It only works, if imagecache ist used to display the picture.

function imagecache_create_url($presetname, $path) {
  $fileinfo = stat($path);
  $path = _imagecache_strip_file_directory($path);
  //check, if path points to profile image
  $picture_path = variable_get('user_picture_path', 'pictures') .'/picture-';
  if (strpos($path, $picture_path) !== false) { 
    return file_create_url(file_directory_path() .'/imagecache/'. $presetname .'/'. $path.'?'.$fileinfo[9]);
  }
  return file_create_url(file_directory_path() .'/imagecache/'. $presetname .'/'. $path);
}
drewish’s picture

well now it's a hack in my module... i don't want a special case in there just for user pictures. a form alter for user pictures doesn't seem that unreasonable.

tantenic’s picture

OK, but the problem is not only on the edit form. The problem is erverwhere the picture is shown. But maybe this is the wrong module to fix that and the wrong issue.

fizk’s picture

Status: Needs work » Closed (fixed)

Not sure if this should be fixed in imagecache. Feel free to discuss.