# Select Dismissal Unexpected Behavior

**URL:** https://meta.discourse.org/t/select-dismissal-unexpected-behavior/201613
**Category:** Support
**Tags:** bulk-actions
**Created:** [August 24, 2021, 11:34pm UTC](https://meta.discourse.org/t/select-dismissal-unexpected-behavior/201613 "2021-08-24T23:34:52Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![forkythetoy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/forkythetoy/32/199298_2.png) [@forkythetoy](https://meta.discourse.org/u/forkythetoy)
#### Post date: [August 24, 2021, 11:34pm UTC](https://meta.discourse.org/t/select-dismissal-unexpected-behavior/201613/1 "2021-08-24T23:34:52Z")

</div>

There was a new feature added in May [Selective dismissal of New and Unread topics](https://meta.discourse.org/t/selective-dismissal-of-new-and-unread-topics/191641/1). We recently just upgraded to the latest discourse, and looking at the code and our DB logs, it seems like when users “Dismiss New” without selecting (ie. just bulk dismiss) we pass in tracked = false and nothing else in the request parameters to reset-new.

![image](https://global.discourse-cdn.com/meta/original/3X/3/e/3e7ae4603421e0e4185f2acef9174f437e345702.png)

Inspecting the PR changes I think we end up here when we try to figure out our topic\_scope [FEATURE: Allow selective dismissal of new and unread topics (#12976) · discourse/discourse@7a79bd7 · GitHub](https://github.com/discourse/discourse/commit/7a79bd7da3e0a59454a3c03f3be31e457d0b9fcc#diff-a672ba5c68f4e7842932ef4e0c0893ef55b981e205a2b85490c4ff4363760811R974)

and because we don’t pass in any topic\_ids we skip the if statement and automatically jump to L989

We run a fairly large discourse server, and I think the notion of just having all Topics is pretty expensive as the query basically generates

```plaintext
LEFT JOIN topic_users ON topic_users.topic_id = topics.id AND topic_users.user_id = xxx WHERE "topics"."deleted_at" IS NULL AND "topics"."id" IN (1, ... 1000000) AND (topics.created_at >= 'date') AND (topic_users.last_read_post_number IS NULL) AND (topics.archetype <> 'private_message') ORDER BY topics.created_at DESC LIMIT 500

```

the IN clause has I believe almost every single topic in the 1M+ range.

Can we default the bulk select to just pass in the topic ids instead of defaulting to all possible Topics?

---

<div class="post-metadata">

### Author: ![Hooksmith](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hooksmith/32/142826_2.png) [@Hooksmith](https://meta.discourse.org/u/Hooksmith)
#### Post date: [August 25, 2021, 12:05pm UTC](https://meta.discourse.org/t/select-dismissal-unexpected-behavior/201613/2 "2021-08-25T12:05:11Z")

</div>

@martin Hey sorry for the notification, looks like you pushed the commit in question linked above.

Any chance you could check if this seems accurate as the root cause of what we’re seeing? We’re seeing huge filter lists in the queries (~a million topic ids) in the default case of “dismiss all new”. (our forum hosts tons of Discourse topics)

We could help with a PR to resolve it if Discourse team has no priority for this, but I doubt we are the only ones affected by this, might also be impacting DB performance of some of your customers.

---

<div class="post-metadata">

### Author: ![martin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin/32/491371_2.png) [@martin](https://meta.discourse.org/u/martin)
#### Post date: [August 25, 2021, 10:33pm UTC](https://meta.discourse.org/t/select-dismissal-unexpected-behavior/201613/3 "2021-08-25T22:33:32Z")

</div>

Thanks @forkythetoy and @Hooksmith for bringing this to my attention, I confirmed this is a huge query even here on meta. I will write a fix for this today, it should be as simple as only using the topic IDs for the topics that show on the New list for a user, rather than _all topics ever_. Will post back here when I have the patch.

---

<div class="post-metadata">

### Author: ![martin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin/32/491371_2.png) [@martin](https://meta.discourse.org/u/martin)
#### Post date: [August 26, 2021, 2:09am UTC](https://meta.discourse.org/t/select-dismissal-unexpected-behavior/201613/5 "2021-08-26T02:09:08Z")

</div>

I merged this fix today:

[https://github.com/discourse/discourse/commit/1646856974be1e96b5d631d4dc89d7d875164f93](https://github.com/discourse/discourse/commit/1646856974be1e96b5d631d4dc89d7d875164f93)

---

<div class="post-metadata">

### Author: ![martin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/martin/32/491371_2.png) [@martin](https://meta.discourse.org/u/martin)
#### Post date: [August 26, 2021, 2:09am UTC](https://meta.discourse.org/t/select-dismissal-unexpected-behavior/201613/6 "2021-08-26T02:09:12Z")

</div>


