Come eliminare migliaia di Messaggi Personali?

La nostra community ha diverse migliaia di messaggi privati che sono stati inviati tra gli utenti. Esiste un modo per rimuovere completamente i messaggi privati con più di 100 risposte dal database (senza possibilità di recupero)?

1 Mi Piace

Well, I think that this will do what you asked. It will delete any private messages that were not created by a system user or discobot. It will still delete any other private messages, including those from admins.

It’s not tested. I’m not saying that it’s a good idea. I won’t promise that it won’t do something bad.

cd /var/discourse
discourse backup
./launcher enter app
rails s
Topic.where(archetype: 'private_message').where("user_id > 0").destroy_all
exit
discourse enable_restore
discourse restore

If something bad does not happen, you can omit the last two steps. If something bad does happen, you’ll want to copy/paste the most recent backup printed by the discourse restore command to restore the backup.

3 Mi Piace

You can remove all message at once.

rake destroy:private_messages

Reference:

6 Mi Piace

Nice work, @IAmGav! I swear i looked there and didn’t see.

3 Mi Piace

Thanks Jay,
Running batch delete query directly on the database is so Scary :sweat_smile:

1 Mi Piace

I took a brief look at how this function works. As it turns out, after running it, all private messages will be deleted.

  def destroy_private_messages
    Topic.where(archetype: "private_message").find_each do |pm|
      @io.puts "Destroying #{pm.slug} pm"
      first_post = pm.ordered_posts.first
      @io.puts PostDestroyer.new(Discourse.system_user, first_post).destroy
    end
  end

I think I have to choose the scary way that @pfaffman pointed out to filter messages. or try to define custom rake function and use PostDestroyer.new(Discourse.system_user, first_post).destroy

2 Mi Piace

Ritornando su questo vecchio argomento, dato che nessuna delle risposte è corretta al 100%.

Il rake task rake destroy:private_messages non elimina definitivamente tutti i messaggi privati, li elimina in modo “soft”. Possono ancora essere visti da un amministratore e possono essere recuperati.

Il codice Rails Topic.where(archetype: 'private_message').where(\"user_id \u003e 0\").destroy_all elimina gli argomenti, ma non i messaggi effettivi. Sono ancora nel database e possono essere visualizzati utilizzando, ad esempio, il plugin data explorer.

Questo codice eliminerà definitivamente tutti i post e gli argomenti dei messaggi privati:
attenzione: coltello affilato qui!

Post.where(topic_id: Topic.where(archetype: 'private_message').where(\"user_id \u003e 0\")).destroy_all
Topic.where(archetype: 'private_message').where(\"user_id \u003e 0\").destroy_all

(e per filtrare questo su argomenti con 100 o più risposte è necessario estendere Topic.where con where(\"posts_count \u003e 100\") in entrambe le righe)

6 Mi Piace