I had to debug this issues like this a couple of times and it’s complicated, so bear with me.
Run the following script and share the output here
# Replace with the topic ID or URL you're debugging
topic_id = 386983
# 1. Check if TopicEmbed exists and its content
te = TopicEmbed.find_by(topic_id: topic_id)
puts "TopicEmbed exists: #{te.present?}"
puts "Embed URL: #{te&.embed_url}"
puts "Content cache present: #{te&.embed_content_cache.present?}"
puts "Content cache length: #{te&.embed_content_cache&.length || 0}"
puts "Content SHA1: #{te&.content_sha1}"
# 2. Check the actual cached content (first 500 chars)
puts "\n--- Cached content preview ---"
puts te&.embed_content_cache&.truncate(500)
# 3. Try fetching from the remote URL
if te&.embed_url.present?
puts "\n--- Attempting remote fetch ---"
begin
response = TopicEmbed.find_remote(te.embed_url)
puts "Remote fetch success: #{response.present?}"
puts "Remote body present: #{response&.body.present?}"
puts "Remote body length: #{response&.body&.length || 0}"
puts "Remote title: #{response&.title}"
puts "Remote body: #{response&.body&.truncate(500)}"
rescue => e
puts "Remote fetch FAILED: #{e.message}"
end
end
# 4. Check what expanded_for would return
if te.present?
puts "\n--- Testing expanded_for ---"
post = Post.find(te.post_id)
# Clear cache to force fresh fetch
Discourse.cache.delete("embed-topic:#{topic_id}")
begin
expanded = TopicEmbed.expanded_for(post)
puts "Expanded content present: #{expanded.present?}"
puts "Expanded content length: #{expanded&.length || 0}"
rescue => e
puts "expanded_for FAILED: #{e.message}"
end
end
# 5. Check relevant settings
puts "\n--- Site Settings ---"
puts "embed_truncate: #{SiteSetting.embed_truncate}"
puts "allowed_embed_selectors: #{SiteSetting.allowed_embed_selectors}"
puts "blocked_embed_selectors: #{SiteSetting.blocked_embed_selectors}"
This will show why https://tecnoblog.net/comunidade/t/governo-renova-app-da-cnh-para-baratear-obtencao-do-documento/157462?u=falco is failing