Deleting 40K topics

Can you not restore from a recent backup?

You might search here for ‘rails delete post’ or, if you have a budget, ask for help in Marketplace.