Ciao a tutti,
sto scrivendo qualcosa per migrare un forum Woltlab (Wbb) a Discourse e sono disposto a condividerlo una volta che sarà più o meno completato.
Al momento sto migrando categorie, forum, utenti e i loro gruppi con successo più o meno, senza troppi problemi. Tuttavia, ogni tanto, durante l’esecuzione, peggiora, ricevo un errore “Ratelimit Exceeded”, durante l’elaborazione dei post e dei thread.
Il mio problema è che sono ancora relativamente nuovo e sto raccogliendo pezzi da altri migratori, quindi al momento non ho idea da dove provenga il messaggio.
Proviene dall’API di Discourse? E se sì, posso in qualche modo disabilitare il ratelimiting durante le importazioni?
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
Ho provato a ripulire il codice e a commentare il più possibile. Spero che qualcuno possa aiutare con il rate limiting.
Ho anche provato a cercare nel forum qui, ma ho visto che molti hanno avuto problemi simili ma mai una vera soluzione. Quindi, se mi è sfuggito qualcosa, mi scuso per il duplicato.
Grazie a tutti.