@@ -30,6 +30,7 @@ class Command(BaseCommand):
30
30
if hasattr (BaseCommand , 'option_list' ): # Django < 1.8
31
31
option_list = BaseCommand .option_list + (
32
32
make_option ('--auto' , action = 'store_true' , dest = 'auto' , default = False ),
33
+ make_option ('--batchsize' , action = 'store' , dest = 'batchsize' , default = 200 , type = int ),
33
34
)
34
35
35
36
def add_arguments (self , parser ):
@@ -43,6 +44,14 @@ def add_arguments(self, parser):
43
44
help = 'Automatically search for models with the '
44
45
'HistoricalRecords field type' ,
45
46
)
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
+ )
46
55
47
56
def handle (self , * args , ** options ):
48
57
to_process = set ()
@@ -65,7 +74,7 @@ def handle(self, *args, **options):
65
74
else :
66
75
self .stdout .write (self .COMMAND_HINT )
67
76
68
- self ._process (to_process )
77
+ self ._process (to_process , batch_size = options [ 'batchsize' ] )
69
78
70
79
def _handle_model_list (self , * args ):
71
80
failing = False
@@ -101,7 +110,7 @@ def _model_from_natural_key(self, natural_key):
101
110
" < {model} >\n " .format (model = natural_key ))
102
111
return model , history_model
103
112
104
- def _process (self , to_process ):
113
+ def _process (self , to_process , batch_size ):
105
114
for model , history_model in to_process :
106
115
if history_model .objects .count ():
107
116
self .stderr .write ("{msg} {model}\n " .format (
@@ -110,5 +119,5 @@ def _process(self, to_process):
110
119
))
111
120
continue
112
121
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 )
114
123
self .stdout .write (self .DONE_SAVING_FOR_MODEL .format (model = model ))
0 commit comments