1212from cloudinary_cli .utils .json_utils import print_json
1313from cloudinary_cli .utils .utils import logger , run_tasks_concurrently , get_user_action
1414
15- DELETE_ASSETS_BATCH_SIZE = 30
15+ _DEFAULT_DELETION_BATCH_SIZE = 30
16+ _DEFAULT_CONCURRENT_WORKERS = 30
1617
1718
1819@command ("sync" ,
2223@argument ("cloudinary_folder" )
2324@option ("--push" , help = "Push changes from your local folder to your Cloudinary folder." , is_flag = True )
2425@option ("--pull" , help = "Pull changes from your Cloudinary folder to your local folder." , is_flag = True )
25- @option ("-w" , "--concurrent_workers" , type = int , default = 30 , help = "Specify number of concurrent network threads." )
26+ @option ("-w" , "--concurrent_workers" , type = int , default = _DEFAULT_CONCURRENT_WORKERS ,
27+ help = "Specify the number of concurrent network threads." )
2628@option ("-F" , "--force" , is_flag = True , help = "Skip confirmation when deleting files." )
2729@option ("-K" , "--keep-unique" , is_flag = True , help = "Keep unique files in the destination folder." )
28- def sync (local_folder , cloudinary_folder , push , pull , concurrent_workers , force , keep_unique ):
30+ @option ("-D" , "--deletion-batch-size" , type = int , default = _DEFAULT_DELETION_BATCH_SIZE ,
31+ help = "Specify the batch size for deleting remote assets." )
32+ def sync (local_folder , cloudinary_folder , push , pull , concurrent_workers , force , keep_unique , deletion_batch_size ):
2933 if push == pull :
3034 raise Exception ("Please use either the '--push' OR '--pull' options" )
3135
32- sync_dir = SyncDir (local_folder , cloudinary_folder , concurrent_workers , force , keep_unique )
36+ sync_dir = SyncDir (local_folder , cloudinary_folder , concurrent_workers , force , keep_unique , deletion_batch_size )
3337
3438 if push :
3539 sync_dir .push ()
@@ -40,12 +44,13 @@ def sync(local_folder, cloudinary_folder, push, pull, concurrent_workers, force,
4044
4145
4246class SyncDir :
43- def __init__ (self , local_dir , remote_dir , concurrent_workers , force , keep_deleted ):
47+ def __init__ (self , local_dir , remote_dir , concurrent_workers , force , keep_deleted , deletion_batch_size ):
4448 self .local_dir = local_dir
4549 self .remote_dir = remote_dir
4650 self .concurrent_workers = concurrent_workers
4751 self .force = force
4852 self .keep_unique = keep_deleted
53+ self .deletion_batch_size = deletion_batch_size
4954
5055 self .verbose = logger .getEffectiveLevel () < logging .INFO
5156
@@ -125,10 +130,10 @@ def _handle_unique_remote_files(self):
125130
126131 logger .info ("Deleting {} resources with type '{}' and resource_type '{}'" .format (len (batch ), * i ))
127132 counter = 0
128- while counter * DELETE_ASSETS_BATCH_SIZE < len (batch ) and len (batch ) > 0 :
133+ while counter * self . deletion_batch_size < len (batch ) and len (batch ) > 0 :
129134 counter += 1
130135 res = api .delete_resources (
131- batch [(counter - 1 ) * DELETE_ASSETS_BATCH_SIZE :counter * DELETE_ASSETS_BATCH_SIZE ], invalidate = True ,
136+ batch [(counter - 1 ) * self . deletion_batch_size :counter * self . deletion_batch_size ], invalidate = True ,
132137 resource_type = i [1 ], type = i [0 ])
133138 num_deleted = reduce (lambda x , y : x + 1 if y == "deleted" else x , res ['deleted' ].values (), 0 )
134139 if self .verbose :
0 commit comments