@@ -30,6 +30,7 @@ class Command(BaseCommand):
3030 if hasattr (BaseCommand , 'option_list' ): # Django < 1.8
3131 option_list = BaseCommand .option_list + (
3232 make_option ('--auto' , action = 'store_true' , dest = 'auto' , default = False ),
33+ make_option ('--batchsize' , action = 'store' , dest = 'batchsize' , default = 200 , type = int ),
3334 )
3435
3536 def add_arguments (self , parser ):
@@ -43,6 +44,14 @@ def add_arguments(self, parser):
4344 help = 'Automatically search for models with the '
4445 'HistoricalRecords field type' ,
4546 )
47+ parser .add_argument (
48+ '--batchsize' ,
49+ action = 'store' ,
50+ dest = 'batchsize' ,
51+ default = 200 ,
52+ type = int ,
53+ help = 'Set a custom batch size when bulk inserting historical records.' ,
54+ )
4655
4756 def handle (self , * args , ** options ):
4857 to_process = set ()
@@ -65,7 +74,7 @@ def handle(self, *args, **options):
6574 else :
6675 self .stdout .write (self .COMMAND_HINT )
6776
68- self ._process (to_process )
77+ self ._process (to_process , batch_size = options [ 'batchsize' ] )
6978
7079 def _handle_model_list (self , * args ):
7180 failing = False
@@ -101,7 +110,7 @@ def _model_from_natural_key(self, natural_key):
101110 " < {model} >\n " .format (model = natural_key ))
102111 return model , history_model
103112
104- def _process (self , to_process ):
113+ def _process (self , to_process , batch_size ):
105114 for model , history_model in to_process :
106115 if history_model .objects .count ():
107116 self .stderr .write ("{msg} {model}\n " .format (
@@ -110,5 +119,5 @@ def _process(self, to_process):
110119 ))
111120 continue
112121 self .stdout .write (self .START_SAVING_FOR_MODEL .format (model = model ))
113- utils .bulk_history_create (model , history_model )
122+ utils .bulk_history_create (model , history_model , batch_size )
114123 self .stdout .write (self .DONE_SAVING_FOR_MODEL .format (model = model ))
0 commit comments