From: Jeremy Stanley Date: Sat, 18 Nov 2017 15:47:39 +0000 (+0000) Subject: Be careful about marking facets modified X-Git-Tag: 0.0.1~115 X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=commitdiff_plain;h=124dd5e224bc2d2cc8af5db6d9e3fc55ed1a8426 Be careful about marking facets modified Make sure to only set the modified flag on a facet when setting a value if it has no corresponding node in its origin or the value differs. This prevents the engine from unnecessarily rewriting the origin's backing file on startup or reload. --- diff --git a/mudpy/misc.py b/mudpy/misc.py index 2da1b40..a23b834 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -129,16 +129,25 @@ class Element: # updated data from files raise PermissionError("Altering elements in read-only files is " "disallowed") + # Coerce some values to appropriate data types + # TODO(fungi) Move these to a separate validation mechanism if facet in ["loglevel"]: value = int(value) elif facet in ["administrator"]: value = bool(value) - if not self.has_facet(facet) or not self.get(facet) == value: - node = ".".join((self.key, facet)) + + # The canonical node for this facet within its origin + node = ".".join((self.key, facet)) + + if node not in self.origin.data or self.origin.data[node] != value: + # Be careful to only update the origin's contents when required, + # since that affects whether the backing file gets written self.origin.data[node] = value - self.facethash[facet] = self.origin.data[node] self.origin.modified = True + # Make sure this facet is included in the element's facets + self.facethash[facet] = self.origin.data[node] + def append(self, facet, value): """Append value to a list.""" newlist = self.get(facet)