i'm having an occasional problem where media mover files from multiple configurations aren't attached to loaded nodes properly, even though they've been processed and completed. i've traced the problem to the media_mover_api_node_files_fetch() function. when a user views a node while the original media files attached to the node are in the midst of being processed (which happens often on my site since cron is run every minute) then the media_mover_api_node_files_fetch() loads incomplete information from the media_mover_files table and caches it. since the cache_media_mover table is never cleared this data is never rebuilt and subsequent views of the node always return this incomplete data, unless the table is manually cleared. my suggested solution is kind of hacky, but should work -- it is to query the status field and return nothing if the status field is ever <> 8 -- that way incomplete configurations are never returned or cached:

function media_mover_api_node_files_fetch($nid) {
// create cache name
$cache_name = 'media_mover_files_node_'. $nid;
// get data from the cache
$data = cache_get($cache_name, 'cache_media_mover');
// we can haz cache?
if (! $data->data) {
$data = array();
$items = db_query('SELECT mmfid, cid, status FROM {media_mover_files} WHERE nid= %d ORDER BY cid', $nid);
while ($item = db_fetch_array($items)) {
if ($item['status'] <> 8) { return; }
$data[$item['cid']][] = media_mover_api_file_fetch($item['mmfid']);
}
cache_set($cache_name, $data, 'cache_media_mover', CACHE_TEMPORARY);
return $data;
}
return $data->data;
}

what do you think?

Comments

arthurf’s picture

Status: Active » Fixed

Ok, this was a situation that I did not anticipate. However, in the latest CVS there is already a fix for this- the media_mover_api_node_files_fetch() will only fetch files that match MMA_FILE_STATUS_COMPLETE_COMPLETE status, so that should duplicate your code above. Secondly, I added cache_clear_all() functions on the cron runs so that things don't get stuck in the cache. Finally, in the D6 version, I added the media mover cache to the cache registery so that it will be cleared by the flush cache function.

arthurf’s picture

Actually, cron was the wrong place to do this. I'm doing the cache clear in media_mover_api_update_file() so that every time the file is updated the cache is wiped. Also the media_mover_api_node_files_fetch() modifications from above are still in place. I think that should take care of every thing you need.

Status: Fixed » Closed (fixed)

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