# Mass closing topics

**URL:** https://meta.discourse.org/t/mass-closing-topics/294004
**Category:** Support
**Created:** [February 2, 2024, 11:14pm UTC](https://meta.discourse.org/t/mass-closing-topics/294004 "2024-02-02T23:14:28Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![hendersj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hendersj/32/507887_2.png) [@hendersj](https://meta.discourse.org/u/hendersj)
#### Post date: [February 2, 2024, 11:14pm UTC](https://meta.discourse.org/t/mass-closing-topics/294004/1 "2024-02-02T23:14:28Z")

</div>

I found this post with instructions on how to use the rails console to mass close topics: [Auto-close old topics from a migrated forum - #10 by zogstrip](https://meta.discourse.org/t/auto-close-old-topics-from-a-migrated-forum/25448/10)

A couple of questions about it, though:

1. Is there a newer way to do this?
2. If I wanted to do the close based on the last activity date (rather than the creation date), is there a variable to use in place of `created_at`?
3. Is there any way to exclude DMs from being closed? I ran the query in my test environment, and noticed that it hit every topic, whether it was public or private; we’d like to exclude private messages if possible.
4. On our forum, we have nearly 16 years of content that we imported from our previous solution. In terms of the time to run the query, (a) how can we determine how long it needs to run, and (b) would it be better to break it up (say, run for everything pre-2010, then for 2011, 2012, etc, until we hit 2023) or just run it as a single query?

Just trying to make sure (with #4) that we don’t impact system performance too much. I know a lot depends on what the hardware is that we’re running on (which I don’t actually know, because we have an infrastructure team that handles the installation itself and maintains all the hardware).

Appreciate any guidance!

---

<div class="post-metadata">

### Author: ![hendersj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hendersj/32/507887_2.png) [@hendersj](https://meta.discourse.org/u/hendersj)
#### Post date: [February 3, 2024, 12:15am UTC](https://meta.discourse.org/t/mass-closing-topics/294004/2 "2024-02-03T00:15:25Z")

</div>

On #2, using the [data explorer](https://meta.discourse.org/t/32566?silent=true) plugin (which I wasn’t aware of), it looks like `updated_at` is probably the value where the ‘last reply timestamp’ would be. Is that an accurate assessment?

---

<div class="post-metadata">

### Author: ![ondrej](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ondrej/32/198804_2.png) [@ondrej](https://meta.discourse.org/u/ondrej)
#### Post date: [February 3, 2024, 12:16am UTC](https://meta.discourse.org/t/mass-closing-topics/294004/3 "2024-02-03T00:16:49Z")

</div>

> [@Administrative Bulk Operations](https://meta.discourse.org/t/administrative-bulk-operations/118349):
>
> Below you will find a collection of bulk operations that can be initiated from the command line. You will need SSH access, so if you are a hosted customer, you will need to contact the Discourse team about running these commands. warning Before working with the console it is extremely important that you have a recent backup. Mistakes can always happen! First thing to do is enter your site’s container: cd /var/discourse ./launcher enter app Additional Guides: [Performing bulk actions a…](https://meta.discourse.org/t/performing-bulk-actions-as-a-moderator/272832)

---

<div class="post-metadata">

### Author: ![hendersj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hendersj/32/507887_2.png) [@hendersj](https://meta.discourse.org/u/hendersj)
#### Post date: [February 3, 2024, 6:17pm UTC](https://meta.discourse.org/t/mass-closing-topics/294004/4 "2024-02-03T18:17:13Z")

</div>

Thanks for this pointer - that’s very useful for my first three questions, I think. Would appreciate some clarity on `updated_at` and planning to operate on our extended history of posts & topics.

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [February 3, 2024, 6:35pm UTC](https://meta.discourse.org/t/mass-closing-topics/294004/5 "2024-02-03T18:35:00Z")

</div>

> [@hendersj](#):
>
> Just trying to make sure (with #4) that we don’t impact system performance too much.

I’d definitely test with a small batch first. I’ve, uh, taken down a community site with bulk actions and wished I tested a subset first.

> **[Calvin and Hobbes by Bill Watterson for November 26, 1986 | GoComics](https://www.gocomics.com/calvinandhobbes/1986/11/26)**
>
> Read Calvin and Hobbes—a comic strip by creator Bill Watterson—for today, November 26, 1986, and check out other great comics, too!

---

<div class="post-metadata">

### Author: ![hendersj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hendersj/32/507887_2.png) [@hendersj](https://meta.discourse.org/u/hendersj)
#### Post date: [February 3, 2024, 6:42pm UTC](https://meta.discourse.org/t/mass-closing-topics/294004/6 "2024-02-03T18:42:31Z")

</div>

Thanks - I suspected that might be the case. Good to have confirmation on the approach.

I think what I may do is see about pulling one of the recent backups and setting up a sandbox environment separate from my test environment. Not sure how the SSO piece will work in that setup, but it would be nice to see what the performance looks like before hitting the prod system.

---

<div class="post-metadata">

### Author: ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)
#### Post date: [February 3, 2024, 6:48pm UTC](https://meta.discourse.org/t/mass-closing-topics/294004/7 "2024-02-03T18:48:34Z")

</div>

That’s a good idea:

> [@Set up a staging server](https://meta.discourse.org/t/set-up-a-staging-server/225951):
>
> There are several tricks that can help when you are setting up a staging server. What is a staging server? A staging server is essentially a clone of a production site. It also resides on a server, and functions identically. It runs inside a Docker container, just as a normal Discourse site does. It exists to give you a place to try risky things out, or to trial things that you cannot easily hide from your users. It is very useful for trialling adverts using the [Discourse Advertising Plugin (A…](https://meta.discourse.org/t/official-advertising-ad-plugin-for-discourse/33734)

I will note that if you have an especially active community, the staging site won’t completely simulate production since there’s some impact from people using the site organically in addition to the bulk actions.

---

<div class="post-metadata">

### Author: ![hendersj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hendersj/32/507887_2.png) [@hendersj](https://meta.discourse.org/u/hendersj)
#### Post date: [February 3, 2024, 7:04pm UTC](https://meta.discourse.org/t/mass-closing-topics/294004/8 "2024-02-03T19:04:07Z")

</div>

Definitely - appreciate the pointer to the staging server post as well - that will be quite helpful.

Yeah, user load is not likely to be a huge issue - looks like our page views per day is around 50K on average across all (crawlers, anonymous, and registered users). Understanding the potential increased load over the existing load will be useful for planning purposes.

---

<div class="post-metadata">

### Author: ![hendersj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hendersj/32/507887_2.png) [@hendersj](https://meta.discourse.org/u/hendersj)
#### Post date: [February 3, 2024, 11:33pm UTC](https://meta.discourse.org/t/mass-closing-topics/294004/9 "2024-02-03T23:33:30Z")

</div>

I did end up setting up a staging server (was pretty easy to do, actually - just restored a backup from prod and logged in using the admin recovery procedure, since it’s configured for OIDC only). Looks like we have about 160K topics, and a quick test on just one category with about 7500 took 6 minutes on my test system - so about 2 hours for all topics. The impact on system performance (monitored with htop) seemed pretty negligible here.

I’m sure we can find a low usage time period where the rake command can be run, and we can stage groups of categories if we want, so that’ll work really nicely for us.

Appreciate all the tips and help - learned a lot about the platform over the last couple of days as a result. 🙂

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [March 4, 2024, 11:33pm UTC](https://meta.discourse.org/t/mass-closing-topics/294004/10 "2024-03-04T23:33:30Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
