迁移主题和帖子时达到访问频率限制

大家好,

我目前正在编写一个将 Woltlab (Wbb) 论坛迁移到 Discourse 的工具,一旦完成,我很乐意分享。

目前,我正在比较顺利地迁移分类、论坛、用户及其群组,没有太多问题。然而,在处理帖子和主题时,偶尔会遇到“Ratelimit Exceeded”(超出速率限制)的错误,而且情况越来越糟。

我的问题是,我相对较新,主要从其他迁移工具中收集零散的代码,所以我目前不清楚这个消息来自哪里。

它来自 Discourse 的 API 吗?如果是,我能否在导入期间完全禁用速率限制?

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

我试图清理代码并尽可能添加注释。希望有人能帮助解决速率限制问题。

我也尝试在这里的论坛搜索过,但只看到很多人有类似的问题,但从未真正解决。所以如果我错过了什么,抱歉重复发帖。

谢谢大家。

2 个赞

好的。字面意思是 RateLimiter.disable

那没事了 :slight_smile:

5 个赞

如果你使用 导入脚本 作为起点,会容易得多。

这将解决你还不知道已经存在的一系列问题。

2 个赞

会是什么问题呢?我目前正在研究 phpbb 和 xenforo 的导入脚本。

1 个赞

phpbb3 脚本写得很好,但需要对 Ruby 有深入的了解。xenforo 还可以,我认为。你应该找一个具有你想要的功能的脚本(私信?永久链接?群组?管理员?被停职用户?)

我猜不到你不知道什么,但连接旧 ID 和新 ID 的方法、确保同一数据不会被导入两次的方法是我想到的两个。

3 个赞

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