Rake posts:rebake_incremental (feature request)

Dear Discourse Developers,

RE: rake posts:rebake (future feature)

rake posts:rebake                                                      # Update each post with latest markdown
rake posts:rebake_match[pattern,type,delay]                            # Rebake all posts matching string/regex and optionally delay the loop

A. Would be great to have a rebake feature which lets the user rebake only if the topic id (or post id) is greater than some integer

rake posts:rebake_incremental['topic_id', 34567]      #Rebakes if topic_id >= 34567
rake posts:rebake_incremental['post_id', 364123]      #Rebakes if  post_id >= 364123

Reasons:

(1) When rebaking, especially when working on migration tasks, developers may have already migrated topics/posts; but then later when they update the migration with new posts (for example in an active forum, when the migration is updated), there is no way (that I am aware of) to specify the starting point in the bake. Pattern matching is not designed for this (unless I am misunderstanding).

(2) When working on fine tuning text from old forums to discourse in migration tasks, for example, fine tuning special char in old forum to work with markdown in a coding forum, or fine tuning recursive bbcode in legacy forums, it is good to rebake, for example, the last 1000 posts (versus the entire DB).

B. Even More Flexible than A (Specify a comparative operator)

rake posts:rebake_incremental['topic_id', '>=',34567]      #Rebakes if topic_id >= 34567
rake posts:rebake_incremental['post_id','<' , 364123]      #Rebakes if  post_id < 364123

Generic:

rake posts:rebake_incremental[target, operator, id]  

Where:

  • target is either the topic_id or the post_id
  • operator is a arithmetic comparison operator
  • id is an integer, either topic_id or post_id

Note: Migration tasks often take a lot of interations to get it right; especially the text and encoding from posts in the original forum to discourse. There are many chars which can be used in a non-markdown-based forums which, when migrated to a markdown-processed forum, cause issues. Having more control over the rebaking process, as illustrated, would help.

3 Likes

There’s also another rake task for rebaking:

rake posts:rebake_uncooked_posts

You could do all the stuff you requested and even more by running the following command in the rails console before executing the rake task from above.

DB.exec(<<~SQL)
  UPDATE posts
  SET baked_version = NULL
  WHERE topic_id >= 34567
SQL

Simply adjust the condition to your special use case. In my book that’s a lot more flexible than a rake task.

11 Likes

Perfect!!!

Thanks @gerhard !!

Totally agree 1000%

Love this rake task and method. It’s so great!

Thank you again!!


Note: One of the great things about this method suggested by @gerhard is that we can bake the last 1000 posts (for example) and if we like the cooked results, then go bake the rest of the 999,000 posts. This is truly a great gem of a feature.

Thank you again


5 Likes