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.

CommentFileSizeAuthor
userreference_valid_uid.patch1.72 KBmcarbone

Comments

NaX’s picture

Works for me.
Thanks.

gracearoha’s picture

works nicely for me also. merci :)

karens’s picture

The 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.

karens’s picture

Status: Needs review » Needs work
karens’s picture

Status: Needs work » Fixed

I 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.

mcarbone’s picture

Yep, that seems to be working. Thanks for improving the fix.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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