여러분 안녕하세요,
현재 Woltlab (Wbb) 포럼을 Discourse로 마이그레이션하는 도구를 작성 중이며, 어느 정도 완성되면 공유할 예정입니다.
현재까지는 카테고리, 포럼, 사용자 및 사용자 그룹을 비교적 문제 없이 성공적으로 마이그레이션하고 있습니다. 그러나 실행 중 가끔씩 상태가 악화되어, 게시물과 스레드를 처리하는 과정에서 “Ratelimit Exceeded”(레이트 리밋 초과) 오류가 발생하고 있습니다.
제 문제는 아직 초보 단계라 다른 마이그레이션 도구들의 코드 조각들을 여기저기서 모아서 사용하고 있는데, 이 메시지가 어디서 발생하는지 전혀 파악이 안 된다는 점입니다.
이 오류는 Discourse API에서 발생하는 것인가요? 그렇다면 가져오기(Import) 과정 동안 레이트 리미팅을 완전히 비활성화할 수 있는 방법이 있을까요?
def migrate_threads_and_posts
puts "Migrating threads and posts..."
@client.query("SELECT * FROM wbb1_thread ORDER BY time ASC").each do |thread_row|
begin
next if thread_row[:isDeleted] == 1 || thread_row[:movedThreadID]
# Ensure lastPosterID maps to a valid user
last_post_user_id = @user_map[thread_row[:lastPosterID]] || @user_map[thread_row[:userID]]
# If lastPosterID and userID are null, create a placeholder user
if last_post_user_id.nil? && thread_row[:lastPoster]
last_post_user_id = find_or_create_placeholder_user(thread_row[:lastPoster])
end
# Ensure a valid user ID exists
last_post_user_id ||= User.first.id
# Get topic creator user ID or create placeholder
creator_user_id = @user_map[thread_row[:userID]] || find_or_create_placeholder_user(thread_row[:username]) || User.first.id
# Create the topic
topic = Topic.new(
title: thread_row[:topic],
user_id: creator_user_id,
category_id: @forum_map[thread_row[:boardID]],
created_at: Time.at(thread_row[:time]),
updated_at: Time.at(thread_row[:lastPostTime]),
last_post_user_id: last_post_user_id
)
if topic.save(validate: false)
puts "Imported thread: #{topic.title} (ID: #{topic.id})"
# Migrate posts
migrate_posts(thread_row[:threadID], topic.id)
else
puts "Error importing thread #{thread_row[:topic]}: #{topic.errors.full_messages.join(', ')}"
end
sleep(7) # Increased sleep to avoid rate limiting
rescue => e
puts "Exception importing thread #{thread_row[:topic]}: #{e.message}"
end
end
end
코드를 최대한 정리하고 주석도 달아 보았습니다. 레이트 리미팅 문제를 도와주실 분이 계셨으면 좋겠습니다.
이 포럼에서도 검색을 해봤는데, 비슷한 문제를 겪는 분들이 많았지만 확실한 해결책은 찾지 못했습니다. 혹시 제가 놓친 부분이 있다면 중복 질문 죄송합니다.
모두 감사합니다.