Speed up import process #2353

We minimised the use of flush() to have only three of them. A first
one to be sure that all Questionnaire have an ID if they are used in
formulas. A second, conditionnal one if a Rule is used in a formula.
And final flush() at the very end of the process.

This result in huge improvement and the import now take ~10% of original time.