示例#1
0
  def _get_snapshottable_objects(self, obj):
    """Get snapshottable objects from parent object's neighborhood."""
    with benchmark("Snapshot._get_snapshotable_objects"):
      related_mappings = set()
      object_rules = self.rules.rules[obj.type]

      with benchmark("Snapshot._get_snapshotable_objects.related_mappings"):
        relatable_rules = {
            rule for rule in object_rules["fst"]
            if isinstance(rule, basestring)
        }

        if relatable_rules:
          related_mappings = obj.related_objects({
              rule for rule in object_rules["fst"]
              if isinstance(rule, basestring)})

      with benchmark("Snapshot._get_snapshotable_objects.direct mappings"):
        direct_mappings = {getattr(obj, rule.name)
                           for rule in object_rules["fst"]
                           if isinstance(rule, Attr)}

      related_objects = {Stub.from_object(obj)
                         for obj in related_mappings | direct_mappings}

      with benchmark("Snapshot._get_snapshotable_objects.fetch neighborhood"):
        return self._fetch_neighborhood(obj, related_objects)
示例#2
0
  def _get_snapshottable_objects(self, obj):
    """Get snapshottable objects from parent object's neighborhood."""
    with benchmark("Snapshot._get_snapshotable_objects"):
      related_mappings = set()
      object_rules = self.rules.rules[obj.type]

      with benchmark("Snapshot._get_snapshotable_objects.related_mappings"):
        relatable_rules = {
            rule for rule in object_rules["fst"]
            if isinstance(rule, basestring)
        }

        if relatable_rules:
          related_mappings = obj.related_objects({
              rule for rule in object_rules["fst"]
              if isinstance(rule, basestring)})

      with benchmark("Snapshot._get_snapshotable_objects.direct mappings"):
        direct_mappings = {getattr(obj, rule.name)
                           for rule in object_rules["fst"]
                           if isinstance(rule, Attr)}

      related_objects = {Stub.from_object(obj)
                         for obj in related_mappings | direct_mappings}

      with benchmark("Snapshot._get_snapshotable_objects.fetch neighborhood"):
        return self._fetch_neighborhood(obj, related_objects)
示例#3
0
 def add_parent(self, obj):
     """Add parent object and automatically scan neighborhood for snapshottable
 objects."""
     with benchmark("Snapshot.add_parent_object"):
         key = Stub.from_object(obj)
         if key not in self.parents:
             with benchmark("Snapshot.add_parent_object.add object"):
                 objs = self._get_snapshottable_objects(obj)
                 self.parents.add(key)
                 self.context_cache[key] = obj.context_id
                 self.children = self.children | objs
                 self.snapshots[key] = objs
         return self.parents
示例#4
0
 def add_parent(self, obj):
   """Add parent object and automatically scan neighborhood for snapshottable
   objects."""
   with benchmark("Snapshot.add_parent_object"):
     key = Stub.from_object(obj)
     if key not in self.parents:
       with benchmark("Snapshot.add_parent_object.add object"):
         objs = self._get_snapshottable_objects(obj)
         self.parents.add(key)
         self.context_cache[key] = obj.context_id
         self.children = self.children | objs
         self.snapshots[key] = objs
     return self.parents