Slight perf improvement for fixtures

This commit is contained in:
zandercymatics 2024-02-23 10:17:52 -07:00
parent 8b56d97712
commit f8f0d7bced
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
4 changed files with 100 additions and 6 deletions

View file

@ -1,5 +1,6 @@
import logging
from faker import Faker
from django.db import transaction
from registrar.models import (
User,
@ -186,5 +187,12 @@ class UserFixture:
@classmethod
def load(cls):
cls.load_users(cls, cls.ADMINS, "full_access_group")
cls.load_users(cls, cls.STAFF, "cisa_analysts_group")
# Lumped under .atomic to ensure we don't make redundant DB calls.
# This bundles them all together, and then saves it in a single call.
# This is slightly different then bulk_create or bulk_update, in that
# you still get the same behaviour of .save(), but those incremental
# steps now do not need to close/reopen a db connection,
# instead they share one.
with transaction.atomic():
cls.load_users(cls, cls.ADMINS, "full_access_group")
cls.load_users(cls, cls.STAFF, "cisa_analysts_group")