Будет ли использование библиотеки Django-Mptt для определения обхода дерева моделей в моем приложении Django повредить производительности моих приложений? - PullRequest
0 голосов
/ 06 декабря 2018

Я использую библиотеку django-mptt django в моих моделях django для хранения иерархических данных в базе данных.

Я построил API бухгалтерского учета, в котором при определении учетных записей есть учетные записи root , parent и children , например учетная запись rootможет быть Assets, тогда Cash Account будет отнесен к категории Актив .

Мой вопрос был, если использование этой библиотеки будет стоить мне особенно высокой производительности. Если кто-то использовал ее, пожалуйста, советуйте.

Ниже приведен пример того, как выглядит моя модель:

class Account(MPTTModel):
    """ Represents an account

    An account may have a parent, and may have zero or more children. Only root
    accounts can have an account_type, all child accounts are assumed to have the same
    account_type as their parent.

    An account's balance is calculated as the sum of all of the transaction Leg's
    referencing the account.

    Attributes:

        uuid (SmallUUID): UUID for account. Use to prevent leaking of IDs (if desired).
        name (str): Name of the account. Required.
        parent (Account|None): Parent account, none if root account
        code (str): Account code. Must combine with account codes of parent
            accounts to get fully qualified account code.
        account_type (str):Also identified as account classification - Type of account as defined by :attr:`Account.TYPES`. Can only be set on
            root accounts. Child accounts are assumed to have the same type as their parent.
        TYPES (Choices): Available account types. Uses ``Choices`` from ``django-model-utils``. Types can be
            accessed in the choice field ``Account.TYPES.asset``, ``Account.TYPES.expense``, etc.
        is_bank_account (bool): Is this a bank account. This implies we can import bank statements into #TODO implement bank statement import in future
            it and that it only supports a single currency.


    """

    TYPES = Choices(
        ("AS", "asset", "Asset"),  # Eg. Cash in bank
        ("LI", "liability", "Liability"),  # Eg. Loans, bills paid after the fact (in arrears)
        ("IN", "income", "Income"),  # Eg. Sales, housemate contributions
        ("EX", "expense", "Expense"),  # Eg. Office supplies, paying bills
        ("EQ", "equity", "Equity"),  # Eg. Money from shares
        ("TR", "trading", "Currency Trading"),  # Used to represent currency conversions
        ("OR", "operating_revenues", "Operating Revenues"),
        ("OX", "operating_expenses", "Operating Expenses"),
        ("NR", "nonoperating_revenues", "Non-Operating Revenues"),
        ("NX", "nonoperating_expenses", "Non-Operating Expenses"),
    )


    uuid = SmallUUIDField(default=uuid_default(), editable=False)
    name = models.CharField(max_length=255,blank=True, null=True)
    parent = TreeForeignKey(
        "self",
        null=True,
        blank=True,
        related_name="children",
        db_index=True,
        on_delete=models.CASCADE,
    )
    code = models.CharField(max_length=3, null=True, blank=True)
    full_code = models.CharField(max_length=100, db_index=True, unique=True, null=True, blank=True)
    account_type = models.CharField(max_length=255,choices=TYPES, blank=True)
    # is_bank_account = models.BooleanField(default=False, blank=True,)
    currencies = ArrayField(models.CharField(max_length=255, db_index=True))
    organization = models.IntegerField(null=False, blank=False)

    objects = AccountManager.from_queryset(AccountQuerySet)()
...