I added a CCK type with a userref field to a database with nearly 400,000 users, but found that I was exhausting php's memory whenever I tried to create a node of that type. It turns out that userreference.module validates uid's by loading every user into an array:
if (!empty($item['uid']) && !in_array($item['uid'], array_keys(_userreference_potential_references($field)))) {
It is totally unnecessary to call _userreference_potential_references here, as we could just query the users table for that uid alone. Here's a patch that does just that, by creating a _userreference_valid_uid function.
This change also probably applies to the D6 branch, but I haven't checked things out there.
| Comment | File | Size | Author |
|---|---|---|---|
| userreference_valid_uid.patch | 1.72 KB | mcarbone |
Comments
Comment #1
NaX commentedWorks for me.
Thanks.
Comment #2
gracearoha commentedworks nicely for me also. merci :)
Comment #3
karens commentedThe patch needs to be adjusted to check for referenceable status, too.
This code duplicates a lot of the work that is done in _userreference_potential_references(), so another approach is to alter that function a bit so you can supply a specific uid to query for in the same way you can specify a string value for a user name and then limit the query to that value. I think I like that approach better because it eliminates code duplication.
Comment #4
karens commentedComment #5
karens commentedI committed a much simpler fix doing what I mentioned in #3 - adding a way to limit the check for referenceable users to a specific uid. Can you confirm that this fixes your problem? If not, I'll go back to your method, but it seems like it should work.
Comment #6
mcarbone commentedYep, that seems to be working. Thanks for improving the fix.
Comment #7
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.