Provide more details when performing a bulk add to group

Problem: We recently tried to add a list of users to a group by adding their email addresses to the Bulk Add to Group page. This list had 191 emails. Upon completion, I got the following message: The users have been added to the group. However, I noticed when later that there were only 127 members of the group. I first figured the list was too long and tried splitting it up, but that didn’t help. I ended up writing a Data Explorer query to get the emails of the members of the group so I could check it against the email list I had, and discovered that some of the emails didn’t exist on the forums, or were duplicated.

Request: More details on the success page if emails did not work. The amount of manual effort required to figure out which emails failed is currently far too high. Ideally, the list of emails (or username) would be displayed with a “success” or “failed” for each. Alternatively, only display the unsuccessful entries.

3 Likes

Can you provide the list to @techapj? Where would errors be logged in this process @techapj?

2 Likes

I’m sorry - how would the list be useful? I’d rather not give out emails for random people even if only shared privately…

Currently the errors are not getting logged at all. If the username/email exists they get added, if not nothing happens.

Added on my list to make this process similar to “Bulk Invite” where admin gets PM with detailed log.

3 Likes

I sent a PR for this:

I replaced success page with a success alert which informs total users added to group.


I spent considerable time on this feature today trying to squeeze the information you asked for, but I realized that it’s not possible without impacting performance.

Initially I thought it will be possible because I have worked on bulk invite feature where we do provide detailed error log via PM. It’s not possible here though because instead of looping through each username/email we simply use IN condition to find out the IDs of users you are trying to add to group. So invalid username/email gets ignored, not resulting in further error. Changing this code to loop through each username/emails will result in significant performance hit when bulk adding thousands of users to a group.

I will discuss this further with @eviltrout to see if there is a possibility to add detailed error log here without significant performance hit.

7 Likes

Thinking out loud here: could this be made a background task, just like exporting one’s posts is?

Getting a number is great, but if I try to add 200 users to a group, and the message says 199 users have been added... that’s not really helpful. It’s better than before - now I’m explicitly told it didn’t get everyone in the list - but I still have to go through a complicated process to figure out which 1 user wasn’t added.

You could probably do it with one query if you did something like this (off the top of my head, untested):

found_users = User.where("username_lower in (:users) OR email IN (:users)", users: users).pluck(:id, :username_lower, :email)

# convert to hash to make searching faster
found_emails = {}
found_usernames = {}

found_users.each do |fu| 
  found_emails[fu[1]] = fu[0]
  found_usernames[fu[2]] = fu[0]
end

not_found = users.reject? {|u| found_emails[u] || found_usernames[u]}

Then not_found would include all the users inputted that weren’t returned by the SQL query.

3 Likes

Awesome, thanks @eviltrout!

I have updated the PR to add more information on “bulk add to group” success page, like so:

EDIT: PR is now merged.

9 Likes

Is that enough @jomaxro?

1 Like

Sure sounds like it! Saw this hit tests_passed, should be able to deploy and test in a few hours.

1 Like

Yep, looks good! Got a nice list of the emails that did not work, thanks @techAPJ!

1 Like

Does it explain why each email “did not work”? What possible reasons are there?

1 Like

The only possible reason is that email/username does not exists. If the user is already present in the group we are not erroring out.

EDIT: I will improve the error message here to point that out.

3 Likes

Nope, just a list of emails.

The only reason I can think of is that the email is not used on the forums, which is exactly what I expected.

Edit: For context, I have a list of “hired staff”. If they’re on my list it means they’ve been hired. It does not mean they’ve signed into our WordPress site, which is what creates their account on the forums (SSO). I’m tracking which emails fail in a spreadsheet to try again later.

Edit 2: One more thing, the list of emails is not sorted in any way, and that’s great! It makes it much easier to compare to my list than if it was, say, sorted alphabetically.

3 Likes