I noticed recently that the Reference Existing Auto-Complete for an image field suddenly stopped listing all available options like it had in the past.

We have heavy re-use of existing files with a required CCK image field. Our users can choose from a series of generic images (e.g. generic-1.jpg, generic-2.jpg) when they don't have one to upload themselves. As it happens, those 10 original images have been re-used hundreds of times.

The issue is that the filefield_source_reference_get_files() call wasn't pulling DISTINCT values and so the first X calls to a particular image were clobbering the remaining references due to the 0,30 limit.

Updating /sources/reference.inc, line 220 to the below fixed the issue for me and all my generic images appear in the auto-complete pulldown.

$result = db_query_range("SELECT DISTINCT f.* FROM {" . $db_info['table'] . "} c INNER JOIN {files} f ON c." . $db_info['columns']['fid']['column'] . " = f.fid WHERE f.filename LIKE '" . $like . "' AND f.status = 1 ORDER BY f.timestamp DESC", $filename, 0, 30);

I'm not sure what other issues, if any, this update makes.

Comments

quicksketch’s picture

Status: Active » Fixed

Thanks for this report. I think the more efficient way of handling this is with a GROUP BY f.fid, so we're only grouping on a single column. Seems that the internet generally considers GROUP BY and DISTINCT to have the same performance benefits, but in the situation where there are multiple columns, I find GROUP BY to be more readable. Anyway, fixed up. Thanks for the report! Though I'm not updating D6 with new features, I've included this fix in both branches.

Status: Fixed » Closed (fixed)

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