django-ddp
django-ddp copied to clipboard
Reactive joins for publications with `user_rel`
(From https://gitter.im/commoncode/django-ddp?at=56551f41bcd12a10513a0be3)
Given the Assessment model:
class Assessment(models.Model):
invited = models.ManyToManyField('auth.user')
Then the following collection will only send Assessments to each user in invited
:
class Assessment(Collection):
"""Assessment DDP Collection."""
model = assessment.Assessment
user_rel = [
'invited',
]
Django DDP will allow the object to be seen if the user is mentioned in ANY of the fields referenced in user_rel
(it applies the OR operator).
Unfortunately I haven't figured out a way to efficiently follow joins in publications yet: we currently have no reactive joins.
Oh hey, I just figured out how to do efficient reactive user_rel
publications!
Note to future self implementing reactive user_rel
publications:
- Only re-process publications for the users mentioned in pre and post change.
eg: signals.m2m_changed(action='pre_add', instance=<User>)
-> only re-process subscriptions for <User>
.