Rebake all posts matching a pattern

(Arpit Jalan) #1

Want to rebake all the posts matching a string or regular expression? Let’s do it!

Access Your Site

First connect to your Droplet via SSH, and enter the Docker container for your Discourse instances:

cd /var/discourse
./launcher enter app

Rebake All Posts Containing a Specific String

Run this command:

rake posts:rebake_match["pattern"]

Replace pattern with the string you want to match. Note that the match performed will be case insensitive.

rake posts:rebake_match[":slight_smile:"]

The above command will rebake all posts which contains :slight_smile: in post raw body.

Rebake All Posts Matching a Regular Expression

To use regular expressions instead of specific string matches:

rake posts:rebake_match["pattern",regex]

PostgreSQL uses POSIX Regular Expressions to perform regex matching. The matching will be case-sensitive.

rake posts:rebake_match["(:slight_smile:|Discourse)",regex]

Rebake all posts containing :slight_smile: or Discourse in post raw body.

rake posts:rebake_match["^Today",regex]

Rebake all posts which starts with Today.

rake posts:rebake_match["^(Today|Yesterday)",regex]

Rebake all posts which starts with Today or Yesterday.

Optional: Add a delay between successive rebakes

In case you want to add a 5 seconds delay between successive rebakes, do:

rake posts:rebake_match["pattern",string,5]

Replace 5 with n (seconds) as per your requirement.

Replace a string in all posts
Migrating to new server quoted post avatar image 404
URL rewrite for domain change in permalinks
Force remote image download after removing disabled domain
How to regenerate the cooked column from the raw
Proxy avatar urls broken in quotes with sub folder install
Unable to undo "censoring a word"
Rebake all posts?
Onebox is broken for some old links
Fix quotes after phpBB import
Moving files to different bucket S3 [AWS]
(Arpit Jalan) #3

A post was split to a new topic: Fixing data after import

(Colin Marshall) #10

Is it possible to rebake all posts from a specific user?

(Jay Pfaffman) #11

Not with that rake task. You could do it from the rails console.
Something like

posts = Post.where (user_id: 123)

posts.each do |p|

(Colin Marshall) #12


One more situation. I migrated a forum from SMF to discourse and there are all these posts that say “Sent from my (device name) using Tapatalk.” I ran a query and got rid of that line from all posts that contained it.

I tired running rake posts:rebake_match["Tapatalk”] but that didn’t work because I’m assuming it matches from the raw post data and that query removed the word I’m trying to match.

Is there a way to I can match against the built html from the rails console?

(Jay Pfaffman) #13
posts = Post.where ("cooked like '%Tapatalk%'")