diff options
author | Tim Laszlo <tim.laszlo@gmail.com> | 2012-10-26 14:14:38 -0500 |
---|---|---|
committer | Tim Laszlo <tim.laszlo@gmail.com> | 2012-10-26 15:36:22 -0500 |
commit | c2e16384931a6789cb6ce49acb11ab47e34d5fa9 (patch) | |
tree | 2f7d6a7bbd88f9d6905d970ac002b1dd51242e9d /src/lib | |
parent | 59b3d315c402e72120d2d12a0f08f58bdff98aeb (diff) | |
download | bcfg2-c2e16384931a6789cb6ce49acb11ab47e34d5fa9.tar.gz bcfg2-c2e16384931a6789cb6ce49acb11ab47e34d5fa9.tar.bz2 bcfg2-c2e16384931a6789cb6ce49acb11ab47e34d5fa9.zip |
Metadata: only write to the database when a change occurs
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Bcfg2/Server/Plugins/Metadata.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Metadata.py b/src/lib/Bcfg2/Server/Plugins/Metadata.py index 83c4db3e0..6daf23476 100644 --- a/src/lib/Bcfg2/Server/Plugins/Metadata.py +++ b/src/lib/Bcfg2/Server/Plugins/Metadata.py @@ -54,9 +54,10 @@ if HAS_DJANGO: raise KeyError(key) def __setitem__(self, key, value): - client = MetadataClientModel.objects.get_or_create(hostname=key)[0] - client.version = value - client.save() + client, created = MetadataClientModel.objects.get_or_create(hostname=key) + if created or client.version != value: + client.version = value + client.save() def __delitem__(self, key): # UserDict didn't require __delitem__, but MutableMapping @@ -544,8 +545,11 @@ class Metadata(Bcfg2.Server.Plugin.Metadata, if attribs is None: attribs = dict() if self._use_db: - client = MetadataClientModel(hostname=client_name) - client.save() + try: + client = MetadataClientModel.objects.get(hostname=client_name) + except MetadataClientModel.DoesNotExist: + client = MetadataClientModel(hostname=client_name) + client.save() self.clients = self.list_clients() return client else: |