perf: 优化会话 命令记录 分片删除 (#12763)

Co-authored-by: feng <1304903146@qq.com>
pull/12766/head
fit2bot 2024-03-06 15:22:55 +08:00 committed by GitHub
parent 670eac49b6
commit 6c89349194
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 2 deletions

View File

@ -86,9 +86,12 @@ def clean_celery_tasks_period():
def batch_delete(queryset, batch_size=3000):
model = queryset.model
count = queryset.count()
with transaction.atomic():
for i in range(0, queryset.count(), batch_size):
queryset[i:i + batch_size].delete()
for i in range(0, count, batch_size):
pks = queryset[i:i + batch_size].values_list('id', flat=True)
model.objects.filter(id__in=list(pks)).delete()
def clean_expired_session_period():