ApprovalQueue: use a materialized table #240
@ -52,17 +52,21 @@ def _update_approval_queue(
|
|||||||
return
|
return
|
||||||
if not created:
|
if not created:
|
||||||
return
|
return
|
||||||
if instance.type not in ApprovalActivity.STATUS_CHANGE_TYPES:
|
|
||||||
return
|
|
||||||
activity_count = ApprovalActivity.objects.filter(extension=instance.extension).count()
|
activity_count = ApprovalActivity.objects.filter(extension=instance.extension).count()
|
||||||
ApprovalQueue.objects.update_or_create(
|
if instance.type in ApprovalActivity.STATUS_CHANGE_TYPES:
|
||||||
extension=instance.extension,
|
ApprovalQueue.objects.update_or_create(
|
||||||
defaults={
|
extension=instance.extension,
|
||||||
'activity_count': activity_count,
|
defaults={
|
||||||
'latest_activity': instance,
|
'activity_count': activity_count,
|
||||||
'sortkey': instance.queue_sortkey,
|
'latest_activity': instance,
|
||||||
},
|
'sortkey': instance.queue_sortkey,
|
||||||
)
|
},
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
if item := ApprovalQueue.objects.filter(extension=instance.extension).first():
|
||||||
|
item.activity_count = activity_count
|
||||||
|
item.save(update_fields={'activity_count'})
|
||||||
|
|
||||||
|
|
||||||
@receiver(pre_delete, sender=ApprovalActivity)
|
@receiver(pre_delete, sender=ApprovalActivity)
|
||||||
|
Loading…
Reference in New Issue
Block a user