What would the best way to import more than 30,000 questions and answers?

7.37K viewsGeneral
1

Hi,

I want to import a huge database of around 30,000 questions and answers.

I have been trying with following code

https://gist.github.com/rahularyan/7b85c9678ddef2c21208

But, it’s causing meta problems (like even after providing user-id activity log says Anonymous answered…, Question/Answers count and reputation points are not updated).

Also I have read your answer on the question Importing from Django

I tried with merging the two, but even that produces some bugs (e.g. questions/answers count, reputation points etc, activity line).

Also the biggest problem I am facing right now, is to import such a large database. It appears to be taking forever to import 30,000 questions, the actual number of queries to be run would be a lot higher, I think (first, 30k questions, then 30k answers, and their meta-entries) .  I have even increased my localhost timeout.

Can you please suggest me –

1. How should I modify this code or what would be the correct code to import all questions and answers from a linear database (questions and answers are in the same row)?

2. What can be done to increase import speed?

Is this q2a from where you are importing ?

No. It’s not q2a. it’s my custom Q&A database created for multiple choice quiz.
and i have customized it for WordPress-Anspress by having columns such as Question_Title(Post_Title), Question_Content(Post_Content), Answer_Content(Post_Content).

When you used to work on q2a themes, I used a similar code to import Q&A to q2a from this database. But back then, it used have approx 5k questions and answers, even then it took me whole day to import (and some days to understand what are other meta I have to include in my custom script). So I am guessing this time it would take days if I blindly do hit and try.

0

So Rahul, I may try using the wp_set_current_user instead of attributing to one user like atultiwari did. How would you set it up in the code atultiwari created above. I get the idea behind the function but I don’t understand how it would be implemented. Not sure how the meta conflicts.

i think, you should set the current user id (from function) in while loop (while ($row = mysql_fetch_array($qry_qbank)) ) where it would pick up question’s / answer’s user id from your database. But I have not tested it. neither I am programmer, So, either make a hit and try or better wait for Rahul to answer it

Gotcha. Yeah i’ve been trying guess and check but its been really frustrating so far because I can’t get it to work right. But this has helped A TON. That makes sense though to put in the loop.

You are viewing 1 out of 3 answers, click here to view all answers.