mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 16:58:46 -03:30
Merge pull request #4319 from cchurch/remove-cached-validated-license-data
Remove caching of validated license data.
This commit is contained in:
@@ -2,9 +2,6 @@
|
|||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.core.cache import cache
|
|
||||||
from django.core.signals import setting_changed
|
|
||||||
from django.dispatch import receiver
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
# Django REST Framework
|
# Django REST Framework
|
||||||
@@ -12,7 +9,6 @@ from rest_framework.exceptions import APIException
|
|||||||
|
|
||||||
# Tower
|
# Tower
|
||||||
from awx.main.task_engine import TaskEnhancer
|
from awx.main.task_engine import TaskEnhancer
|
||||||
from awx.main.utils import memoize
|
|
||||||
|
|
||||||
__all__ = ['LicenseForbids', 'get_license', 'get_licensed_features',
|
__all__ = ['LicenseForbids', 'get_license', 'get_licensed_features',
|
||||||
'feature_enabled', 'feature_exists']
|
'feature_enabled', 'feature_exists']
|
||||||
@@ -23,18 +19,10 @@ class LicenseForbids(APIException):
|
|||||||
default_detail = _('Your Tower license does not allow that.')
|
default_detail = _('Your Tower license does not allow that.')
|
||||||
|
|
||||||
|
|
||||||
@memoize(cache_key='_validated_license_data')
|
|
||||||
def _get_validated_license_data():
|
def _get_validated_license_data():
|
||||||
return TaskEnhancer().validate_enhancements()
|
return TaskEnhancer().validate_enhancements()
|
||||||
|
|
||||||
|
|
||||||
@receiver(setting_changed)
|
|
||||||
def _on_setting_changed(sender, **kwargs):
|
|
||||||
# Clear cached result above when license changes.
|
|
||||||
if kwargs.get('setting', None) == 'LICENSE':
|
|
||||||
cache.delete('_validated_license_data')
|
|
||||||
|
|
||||||
|
|
||||||
def get_license(show_key=False):
|
def get_license(show_key=False):
|
||||||
"""Return a dictionary representing the active license on this Tower instance."""
|
"""Return a dictionary representing the active license on this Tower instance."""
|
||||||
license_data = _get_validated_license_data()
|
license_data = _get_validated_license_data()
|
||||||
|
|||||||
@@ -26,16 +26,13 @@ def handle_setting_change(key, for_delete=False):
|
|||||||
# When a setting changes or is deleted, remove its value from cache along
|
# When a setting changes or is deleted, remove its value from cache along
|
||||||
# with any other settings that depend on it.
|
# with any other settings that depend on it.
|
||||||
setting_keys = [key]
|
setting_keys = [key]
|
||||||
setting_key_dict = {}
|
|
||||||
setting_key_dict[key] = key
|
|
||||||
for dependent_key in settings_registry.get_dependent_settings(key):
|
for dependent_key in settings_registry.get_dependent_settings(key):
|
||||||
# Note: Doesn't handle multiple levels of dependencies!
|
# Note: Doesn't handle multiple levels of dependencies!
|
||||||
setting_keys.append(dependent_key)
|
setting_keys.append(dependent_key)
|
||||||
setting_key_dict[dependent_key] = dependent_key
|
|
||||||
cache_keys = set([Setting.get_cache_key(k) for k in setting_keys])
|
cache_keys = set([Setting.get_cache_key(k) for k in setting_keys])
|
||||||
logger.debug('sending signals to delete cache keys(%r)', cache_keys)
|
logger.debug('sending signals to delete cache keys(%r)', cache_keys)
|
||||||
cache.delete_many(cache_keys)
|
cache.delete_many(cache_keys)
|
||||||
clear_cache_keys.delay(setting_key_dict)
|
clear_cache_keys.delay(list(cache_keys))
|
||||||
|
|
||||||
# Send setting_changed signal with new value for each setting.
|
# Send setting_changed signal with new value for each setting.
|
||||||
for setting_key in setting_keys:
|
for setting_key in setting_keys:
|
||||||
|
|||||||
Reference in New Issue
Block a user