# Provide more details when performing a bulk add to group

**URL:** https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665
**Category:** Feature
**Tags:** groups
**Created:** [9 أبريل 2017، 3:37ص UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665 "2017-04-09T03:37:56Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [9 أبريل 2017، 3:37ص UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/1 "2017-04-09T03:37:56Z")

</div>

**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](https://meta.discourse.org/t/32566?silent=true) 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.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [9 أبريل 2017، 3:42ص UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/2 "2017-04-09T03:42:03Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [9 أبريل 2017، 3:43ص UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/3 "2017-04-09T03:43:43Z")

</div>

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

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [10 أبريل 2017، 9:43ص UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/4 "2017-04-10T09:43:00Z")

</div>

> [@codinghorror](#):
>
> Where would errors be logged in this process @techapj?

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.

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [26 أبريل 2017، 5:09م UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/5 "2017-04-26T17:09:48Z")

</div>

I sent a PR for this:

[https://github.com/discourse/discourse/pull/4839](https://github.com/discourse/discourse/pull/4839)

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

 ![](https://global.discourse-cdn.com/meta/original/3X/d/9/d959804f073a7a00542ea6adde2af3a21bfe1b6a.png)

* * *

> [@jomaxro](#):
>
> Ideally, the list of emails (or username) would be displayed with a “success” or “failed” for each. Alternatively, only display the unsuccessful entries.

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](https://github.com/discourse/discourse/blob/7a9eee1b71cf298210ee9a258e9f17ae1a8a9af7/app/controllers/admin/groups_controller.rb#L29) 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.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [26 أبريل 2017، 5:13م UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/6 "2017-04-26T17:13:11Z")

</div>

> [@techAPJ](#):
>
> Changing this code to loop through each username/emails will result in significant performance hit when bulk adding thousands of users to a group.

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.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [26 أبريل 2017، 5:19م UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/7 "2017-04-26T17:19:44Z")

</div>

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

```ruby
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.

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [26 أبريل 2017، 7:19م UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/8 "2017-04-26T19:19:30Z")

</div>

Awesome, thanks @eviltrout!

I have updated [the PR](https://github.com/discourse/discourse/pull/4839) to add more information on “bulk add to group” success page, like so:

 ![](https://global.discourse-cdn.com/meta/original/3X/6/a/6afd2e380fdf3dd8fd51332450ebf92b5ea4891d.png)

EDIT: PR is now merged.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [27 أبريل 2017، 12:01ص UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/9 "2017-04-27T00:01:32Z")

</div>

Is that enough @jomaxro?

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [27 أبريل 2017، 12:02ص UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/10 "2017-04-27T00:02:10Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [27 أبريل 2017، 2:15ص UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/11 "2017-04-27T02:15:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [27 أبريل 2017، 2:16ص UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/12 "2017-04-27T02:16:44Z")

</div>

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

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [27 أبريل 2017، 2:18ص UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/13 "2017-04-27T02:18:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [27 أبريل 2017، 2:18ص UTC](https://meta.discourse.org/t/provide-more-details-when-performing-a-bulk-add-to-group/60665/14 "2017-04-27T02:18:52Z")

</div>

> [@codinghorror](#):
>
> Does it explain why each email “did not work”?

Nope, just a list of emails.

> [@codinghorror](#):
>
> What possible reasons are there?

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.
