further optimize conf.settings access when logging is enabled

the callback receiver is still fairly slow when logging is enabled due
to constant setting lookups; this speeds things up considerably

related: https://github.com/ansible/awx/pull/5618
This commit is contained in:
Ryan Petrello
2020-01-22 14:09:18 -05:00
parent 046518ab8f
commit e18639b26b
3 changed files with 40 additions and 19 deletions

View File

@@ -1,5 +1,4 @@
# Python
from collections import namedtuple
import contextlib
import logging
import re
@@ -136,6 +135,15 @@ def filter_sensitive(registry, key, value):
return value
class TransientSetting(object):
__slots__ = ('pk', 'value')
def __init__(self, pk, value):
self.pk = pk
self.value = value
class EncryptedCacheProxy(object):
def __init__(self, cache, registry, encrypter=None, decrypter=None):
@@ -186,8 +194,6 @@ class EncryptedCacheProxy(object):
self.set(key, value, log=False, **kwargs)
def _handle_encryption(self, method, key, value):
TransientSetting = namedtuple('TransientSetting', ['pk', 'value'])
if value is not empty and self.registry.is_setting_encrypted(key):
# If the setting exists in the database, we'll use its primary key
# as part of the AES key when encrypting/decrypting