@@ -113,11 +113,15 @@ def get_indexing_queryset(
113113 if verbose :
114114 stdout .write (f"{ action } { model } : 0% ({ self ._eta (start , done , count )} )\r " )
115115
116+ if count == 0 :
117+ stdout .write (f"No { model } objects to { action .lower ()} .\n " )
118+ return
119+
116120 if batch_type == "pk_filters" :
117121 pks = qs .aggregate (min = Min ("pk" ), max = Max ("pk" ))
118122 total_batches = (pks ["max" ] - pks ["min" ]) // chunk_size
119123 for batch_number , offset in enumerate (range (pks ["min" ], pks ["max" ] + 1 , chunk_size ), start = 1 ):
120- batch_qs = list (copy . deepcopy ( qs .filter (pk__gte = offset , pk__lt = offset + chunk_size ) ))
124+ batch_qs = list (qs .filter (pk__gte = offset , pk__lt = offset + chunk_size ))
121125 stdout .write (f"Processing batch { batch_number } /{ total_batches } : \n " )
122126 for obj in batch_qs :
123127 done += 1
@@ -127,11 +131,11 @@ def get_indexing_queryset(
127131 )
128132 yield obj
129133 if len (batch_qs ) > 0 :
130- stdout .write (f"Max primary key in the current batch: { batch_qs [- 1 ].pk } \n " )
134+ stdout .write (f"Max primary key in the current { model } batch: { batch_qs [- 1 ].pk } \n " )
131135 else :
132136 total_batches = (count + chunk_size - 1 ) // chunk_size
133137 for batch_number , offset in enumerate (range (0 , count , chunk_size ), start = 1 ):
134- batch_qs = list (copy . deepcopy ( qs [offset : offset + chunk_size ].all () ))
138+ batch_qs = list (qs [offset : offset + chunk_size ].all ())
135139 stdout .write (f"Processing batch { batch_number } /{ total_batches } : \n " )
136140 for obj in batch_qs :
137141 done += 1
@@ -141,7 +145,7 @@ def get_indexing_queryset(
141145 )
142146 yield obj
143147 if len (batch_qs ) > 0 :
144- stdout .write (f"Max primary key in the current batch: { batch_qs [- 1 ].pk } \n " )
148+ stdout .write (f"Max primary key in the current { model } batch: { batch_qs [- 1 ].pk } \n " )
145149
146150 def init_prepare (self ):
147151 """Initialise the data model preparers once here.
0 commit comments