models.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:django-eventstream 作者: fanout 项目源码 文件源码
def save(self, *args, **kwargs):
        if not self.eid:
            counter = EventCounter.get_or_create(self.channel)

            with transaction.atomic():
                counter = EventCounter.objects.select_for_update(
                    ).get(id=counter.id)
                self.eid = counter.value + 1

                try:
                    super(Event, self).save(*args, **kwargs)
                except Exception:
                    self.eid = 0
                    raise

                counter.value = self.eid
                counter.save()
        else:
            super(Event, self).save(*args, **kwargs)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号