Old LazyYT cooked posts have not been rebaked after lazy-yt was replaced with lazy-video

Looks like right now in my forums I have hundreds or thousands of blank posts or posts just missing youtube videos and the reason seems to be that baked post content looks like this:

<div class="cooked">
<div class="lazyYT" data-youtube-id="WJxSNbAer9M" data-youtube-title="Starset - Die For You (Official Audio)" data-width="480" data-height="270" data-parameters="feature=oembed&amp;wmode=opaque">
</div>
</div>

If I rebuild HTML YouTube videos are cooked correctly using lazy-video-wrapper.

I did some digging and seems that this problem maybe related to this PR: DEV: Remove lazy-yt and replace with lazy-videos by jancernik · Pull Request #20722 · discourse/discourse · GitHub For some reason after this change not all posts got rebaked. I’m not a SQL or Discourse guy so I’m not sure if the problem is in migration script it self or in that it failed at some point.

class RebakeLazyYtPosts < ActiveRecord::Migration[7.0]
  def up
    execute <<~SQL
      UPDATE posts SET baked_version = 0
      WHERE cooked LIKE '%lazyYT-container%'
    SQL
  end

Seems that I need to rebake a couple of thousand posts with youtube links in them. How should I go about doing it?

1 Like

I think it’s possible to be rate-limited by YouTube when rebaking a large amount of posts. You may want to consider doing it in batches with a delay to avoid hitting it again.

1 Like

Could you point me in a direction of a reference on how to do it? I suppose a way which would not require an active terminal session.

I did not delve into why my posts were not rebaked so it remains a mystery. If somebody encounters this problem and wants to rebake manually their posts this is how i did go about it:

Enter Rails console:

cd /var/discourse
./launcher enter app
rails c

And I did run this script:

posts = Post.where ("cooked like '%lazyYT%'")
posts.each do |p|
    p.rebake!     
    sleep 1 
end

One post per second is slower than I would like, but I wanted to be extra sure that I will not hit any YouTube limits if there are any. For 12 000 posts it was not that bad of a wait.

2 Likes

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