-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support bulk operations #448
base: master
Are you sure you want to change the base?
Conversation
I have not understand the feature exactly. Can you elaborate more of the feature and add some documentation? |
Thanks for the answer! Of course, I'll tell you more about the feature. In the process of working with the library, I came across the fact that bulk creation/updating of objects does not provide for calling the update of documents in the index. Thus, the following constructs will update rows in the database, but the changes will not affect the elasticsearch indexes:
All these operations are operations of bulk creating/updating Since django does not serve signals for the operations I have listed, except for So, to support the current state of the elasticsearch index, I described a manager for working with bulk operations that can be connected to models that require it via the In the manager implementation itself, I applied the I also want to focus special attention on signal processing for mass deletion of objects. In order to correctly process the built-in django signal in the signal processor implementation, a check of the key parameter |
Thanks for describing the scenario @kirillpechurin, I can understand it now. Let me think if it can be solved in any easier way. I will get back to it within one week. Feel free to ping me if I do not write any comment here! 😅 |
@safwanrahman I have not received an answer from you. Tell me, please, did you manage to think of a easier way? 🙂 |
Hi @kirillpechurin, |
In order to support the actual state of documents in indexes, I propose a solution to support bulk operations via manager implementation
A manager is described for working with the following bulk operations:
bulk_create
bulk_update
update
delete
Manager can be connected to the model by calling
as_manager()
in theobjects
attribute.The manager itself is implemented in a similar way to the signal processor. The manager is described using the Mixin approach, allowing you to connect additional functionality to existing managers. The mixin contains functions that call
registry
. The process of working with registry for massoperations boils down to the following: entities are received by IDs, these entities are normalized and sent to registryTo update related entities, the update occurs with an additional
many
flag.The
many
flag is introduced to get target entities from related from a queryset or a list.The following has been adjusted for registry:
many
flag for update functions on related entities. With themany
flag, the document functionget_instances_from_many_related
is called. Theget_instances_from_many_related
function receives the entity class and the selection of related entities itself as inputModel
QuerySet
list
A check has been introduced into the existing signal processor for the correct processing of the following deletion signals:
handle_pre_delete
handle_delete
For these functions, a check of the key parameter
origin
has been introduced in order to reduce the operation of the signal only when interacting with a specific entity.To process the signal by m2m changes, the transmission of
origin
as a key parameter has been introduced. Theorigin
parameter is passed as a call to the class of the model from which the signal was receivedAdded in the
get_value_from_instance
(DEDField) function to work withCompleted and updated testing
Updated readme. Add
Support bulk operations.