From ef91ebb46883696539b0e90ff9f9c54f81eebe20 Mon Sep 17 00:00:00 2001 From: wangruidong <940853815@qq.com> Date: Tue, 10 Sep 2024 15:04:41 +0800 Subject: [PATCH] perf: clean expired and account is null SyncInstanceTask record --- apps/ops/mixin.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/ops/mixin.py b/apps/ops/mixin.py index 9e884ee4b..ab312826a 100644 --- a/apps/ops/mixin.py +++ b/apps/ops/mixin.py @@ -16,6 +16,13 @@ __all__ = [ ] +class PeriodTaskModelQuerySet(models.QuerySet): + def delete(self, *args, **kwargs): + for obj in self: + obj.delete() + return super().delete(*args, **kwargs) + + class PeriodTaskModelMixin(models.Model): name = models.CharField( max_length=128, unique=False, verbose_name=_("Name") @@ -27,6 +34,7 @@ class PeriodTaskModelMixin(models.Model): crontab = models.CharField( blank=True, max_length=128, null=True, verbose_name=_("Crontab"), ) + objects = PeriodTaskModelQuerySet.as_manager() @abc.abstractmethod def get_register_task(self):