From 4072aee887c9db19f67bb57aae02ebe6456e2c8b Mon Sep 17 00:00:00 2001 From: Eg0ra Date: Thu, 19 Dec 2024 14:35:03 +0700 Subject: [PATCH] Improve docstring for update_task_status --- import_export_extensions/resources.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/import_export_extensions/resources.py b/import_export_extensions/resources.py index 16a7f93..59efd00 100644 --- a/import_export_extensions/resources.py +++ b/import_export_extensions/resources.py @@ -266,17 +266,29 @@ def update_task_state( ): """Update state of the current event. - Receives meta of the current task and increase the `current`. + Receives meta of the current task and increase the `current`. Task + state is updated when current item is a multiple of + `self.status_update_row_count` or equal to total number of items. + + For example: once every 1000 objects (if the current object is 1000, + 2000, 3000) or when current object is the last object, in order to + complete the import/export. + + This needed to increase the speed of import/export by reducing number + of task status updates. """ if not current_task or current_task.request.called_directly: return self.current_object_number += 1 - if ( + + is_reached_update_count = ( self.current_object_number % self.status_update_row_count == 0 - or self.current_object_number == self.total_objects_count - ): + ) + is_last_object = self.current_object_number == self.total_objects_count + + if is_reached_update_count or is_last_object: self._update_current_task_state( state=state, meta={