مرحباً بالجميع،
أنا أكتب حاليًا شيئًا لترحيل منتدى Woltlab (Wbb) إلى Discourse وأنا على استعداد لمشاركته بمجرد الانتهاء منه إلى حد ما.
في الوقت الحالي، أقوم بترحيل الفئات والمنتديات والمستخدمين ومجموعاتهم بنجاح إلى حد ما دون الكثير من المشاكل. ومع ذلك، بين الحين والآخر، أثناء التشغيل، يصبح الأمر أسوأ، وأحصل على خطأ “Ratelimit Exceeded”، أثناء معالجة المشاركات والمواضيع.
مشكلتي هي أنني ما زلت جديدًا نسبيًا وأقوم بجمع أجزاء من أدوات ترحيل أخرى، لذا فأنا حاليًا في حيرة من أمري بشأن مصدر الرسالة.
هل تأتي من واجهة برمجة تطبيقات Discourse؟ وإذا كان الأمر كذلك، هل يمكنني تعطيل تحديد المعدل أثناء عمليات الاستيراد تمامًا؟
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
لقد حاولت تنظيف الكود والتعليق قدر الإمكان. آمل أن يتمكن شخص ما من المساعدة في تحديد المعدل.
لقد حاولت أيضًا البحث في المنتدى هنا ولكنني رأيت فقط أن الكثيرين لديهم مشاكل مماثلة ولكن لم يتم حلها حقًا. لذا إذا فاتني شيء ما، فاعذرني على التكرار.
شكرا للجميع.