mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
Setting caching (#3178)
* Revert "Remove stat context variables" This reverts commit0989c308d0
. * Add a caching framework for inventree settings - Actions that use "settings" require a DB hit every time - For example the part.full_name() method looks at the PART_NAME_FORMAT setting - This means 1 DB hit for every part which is serialized!! * Fixes for DebugToolbar integration - Requires different INTERNAL_IPS when running behind docker - Some issues with TEMPLATES framework * Revert "Revert "Remove stat context variables"" This reverts commit52e6359265
. * Add unit tests for settings caching * Update existing unit tests to handle cache framework * Fix for unit test * Re-enable cache for default part values * Clear cache for further unit tests
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.test import TestCase
|
||||
|
||||
@ -394,6 +395,9 @@ class PartSettingsTest(InvenTreeTestCase):
|
||||
|
||||
def make_part(self):
|
||||
"""Helper function to create a simple part."""
|
||||
|
||||
cache.clear()
|
||||
|
||||
part = Part.objects.create(
|
||||
name='Test Part',
|
||||
description='I am but a humble test part',
|
||||
@ -404,6 +408,9 @@ class PartSettingsTest(InvenTreeTestCase):
|
||||
|
||||
def test_defaults(self):
|
||||
"""Test that the default values for the part settings are correct."""
|
||||
|
||||
cache.clear()
|
||||
|
||||
self.assertTrue(part.settings.part_component_default())
|
||||
self.assertTrue(part.settings.part_purchaseable_default())
|
||||
self.assertFalse(part.settings.part_salable_default())
|
||||
@ -411,6 +418,9 @@ class PartSettingsTest(InvenTreeTestCase):
|
||||
|
||||
def test_initial(self):
|
||||
"""Test the 'initial' default values (no default values have been set)"""
|
||||
|
||||
cache.clear()
|
||||
|
||||
part = self.make_part()
|
||||
|
||||
self.assertTrue(part.component)
|
||||
|
Reference in New Issue
Block a user