Migrate a NodeBB forum with MongoDB to Discourse

어떻게든 스크립트 함수를 정상적으로 작동하게 만들었습니다.

아래는 제 변경 사항입니다 (Claude Code의 작은 도움 덕분에 :slight_smile:)

 >>mongo.rb
   
   def posts(offset = 0, page_size = 1000)
      post_keys = mongo.find(_key: "posts:pid").skip(offset).limit(page_size).pluck(:value)
      post_keys
          .map { |pid| post(pid) }
          .compact  # <-- nil 결과(고아 pid) 제거
      post_keys.map { |post_key| post(post_key) }
    end

    def post(id)
    post = mongo.find(_key: "post:#{id}").first
    return nil if post.nil? # <-- null 체크
    post["timestamp"] = timestamp_to_date(post["timestamp"])
    if post["upvoted_by"] = mongo.find(_key: "pid:#{id}:upvote").first
        post["upvoted_by"] = mongo.find(_key: "pid:#{id}:upvote").first[:members]
      else
        post["upvoted_by"] = []
      end

      post["pid"] = post["pid"].to_s
      post["deleted"] = post["deleted"].to_s

      post
    end
	
>>nodebb.rb

 create_posts(posts, total: post_count, offset: offset) do |post|
        # post가 null이면 건너뜀
		# merged_post인 경우 건너뜀
        next if post.nil?
        next if @merged_posts_map[post["pid"]]

        # 삭제된 경우 건너뜀
        next if post["deleted"] == "1"

        raw = post["content"]
        post_id = "p#{post["pid"]}"

        next if raw.blank?
        topic = topic_lookup_from_imported_post_id("t#{post["tid"]}")

        unless topic
          puts "Topic with id #{post["tid"]} not found, skipping"
          next
        end	

이제 제대로 작동하는 것 같습니다.

Discourse의 내부 아키텍처 관점에서 이것이 얼마나 정확한지는 알 수 없지만, 첫눈에 보기에는 작동하는 것 같습니다.

개선 및 최적화에 대한 제안은 언제든지 환영합니다.

1개의 좋아요