I'm parsing poker hand histories, and storing the data in a postgres database. Here's a quick view of that:

I'm getting a relatively bad performance, and parsing files will take several hours. I can see that the database part takes 97% of the total program time. So only a little optimization would make this a lot quicker.
The way I have it set-up now is as follows:
- Read next file into a string.
- Parse one game and store it into object GameData.
- For every player, check if we have his name in the std::map. If so; store the playerids in an array and go to 5.
- Insert the player, add it to the std::map, store the playerids in an array.
- Using the playerids array, insert the moves for this betting round, store the moveids in an array.
- Using the moveids array, insert a movesequence, store the movesequenceids in an array.
- If this isn't the last round played, go to 5.
- Using the movesequenceids array, insert a game.
- If this was not the final game, go to 2.
- If this was not the last file, go to 1.
Since I'm sending queries for every move, for every movesequence, for every game, I'm obviously doing too many queries. How should I bundle them for best performance? I don't mind rewriting a bit of code, so don't hold back. :)
Thanks in advance.
CX