A somewhat different proposal is in ticket #17824: Add generic pre/post_modify 
signal. I think the generic
"object modified" signals would fit your use case very well.

The idea is that there would be just one signal which would be fired for any 
data modifying ORM operation.
The arguments for it:
  - fired for every operation modifying data
  - one signal to listen to for all data modifications
The likely counter-arguments:
  - duplicates the existing signals
  - the callbacks end up being a big "switch statement", and thus you end up 
separating save, delete etc
anyways.
  - the API isn't good enough

>From performance perspective there should be no big problems: the signal is 
>given an iterable as
"objs_modified" argument. For .update() for example, where you don't want to 
fetch all the objects for
performance reasons, you could just pass qs.filter(update_filters) as the 
modified objects. This way
there would be no performance penalty, except if there is actual use of the 
signal.

I would like to see a generic pre/post modify signal, as I think it is much 
easier to use than using
the pre/post save/delete + m2m_changed signals. However, I do not feel strongly 
at all about this, just
something I would find useful. I believe having total control of all data 
modifying operations using Django
signals would be a welcome addition for many users.

 - Anssi
________________________________________
From: django-developers@googlegroups.com [django-developers@googlegroups.com] 
On Behalf Of Byron Ruth [bjr...@gmail.com]
Sent: Sunday, March 25, 2012 17:46
To: django-developers@googlegroups.com
Subject: Add signals for QuerySet bulk operations such as `delete`, `update, 
`bulk_create`

My use case is for regenerating aggregate data cache at a table level. Simply 
calling a single signal after a bulk operation is complete would enable 
invalidating such aggregate cache. There is not a very clean alternate solution 
to this problem unless using database triggers which calls an external script 
that invalidates the cache.

--
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-developers/-/DAaTRIau8h8J.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to