fcm-django icon indicating copy to clipboard operation
fcm-django copied to clipboard

Emit signal on active change

Open BojanKogoj opened this issue 7 years ago • 2 comments

active is being changed through update(), which does not emit a signal that I need. Would it make sense to add signal to update?

Something similar to the following in https://github.com/xtrinch/fcm-django/blob/master/fcm_django/models.py#L38

class FCMDeviceQuerySet(models.query.QuerySet):

    def update(self, **kwargs):
        post_save.send(self.__class__, **kwargs)  # some signal
        return super(FCMDeviceQuerySet, self).update(**kwargs)

BojanKogoj avatar May 31 '17 08:05 BojanKogoj

Well the question at hand is how much worse will the performance be, if you call save on individual models so that the post_save handler would be triggered.

What is the use case of using post_save? Is it anything that could be handled differently?

xtrinch avatar May 31 '17 11:05 xtrinch

I think adding a signal for something scalable like notifications would be potentially harmful. Over at djangorestframework-simplejwt, I considered the same problem and came to the conclusion that we could add a setting saying whether we wanted to emit a signal. I don't think a signal will be necessary though. On the one hand, if a device is being deactivated, you can receive the ids from the QuerySet API response (from #160). From DRF, override some views. And from admins, override the ModelAdmin class

Andrew-Chen-Wang avatar Jul 02 '21 06:07 Andrew-Chen-Wang