@@ -160,8 +160,14 @@ def track_database_path(self, database_path: DatabasePath) -> None:
160160 self .timestamp_status_map [database_path .attribute_changed_at ] = database_path .attribute_status
161161
162162 def to_diff_attribute (self , from_time : Timestamp ) -> DiffAttribute :
163- properties = [prop .to_diff_property (from_time = from_time ) for prop in self .properties_by_type .values ()]
163+ properties = []
164+ for prop in self .properties_by_type .values ():
165+ diff_prop = prop .to_diff_property (from_time = from_time )
166+ if diff_prop .action is not DiffAction .UNCHANGED :
167+ properties .append (diff_prop )
164168 action , changed_at = self .get_action_and_timestamp (from_time = from_time )
169+ if not properties :
170+ action = DiffAction .UNCHANGED
165171 return DiffAttribute (
166172 uuid = self .uuid , name = self .name , changed_at = changed_at , action = action , properties = properties
167173 )
@@ -262,11 +268,15 @@ def get_final_single_relationship(self, from_time: Timestamp) -> DiffSingleRelat
262268 chronological_properties = peer_id_properties , from_time = from_time
263269 )
264270 peer_id = peer_final_property .new_value or peer_final_property .previous_value
265- other_final_properties = [
266- self ._get_single_relationship_final_property (chronological_properties = property_list , from_time = from_time )
267- for property_type , property_list in self .ordered_properties_by_type .items ()
268- if property_type != DatabaseEdgeType .IS_RELATED
269- ]
271+ other_final_properties = []
272+ for property_type , property_list in self .ordered_properties_by_type .items ():
273+ if property_type is DatabaseEdgeType .IS_RELATED :
274+ continue
275+ final_prop = self ._get_single_relationship_final_property (
276+ chronological_properties = property_list , from_time = from_time
277+ )
278+ if final_prop .action is not DiffAction .UNCHANGED :
279+ other_final_properties .append (final_prop )
270280 final_properties = [peer_final_property ] + other_final_properties
271281 last_changed_property = max (final_properties , key = lambda fp : fp .changed_at )
272282 last_changed_at = last_changed_property .changed_at
@@ -330,8 +340,8 @@ def to_diff_relationship(self, from_time: Timestamp) -> DiffRelationship:
330340 single_relationships = [
331341 sr .get_final_single_relationship (from_time = from_time ) for sr in self ._single_relationship_list
332342 ]
333- last_changed_relatonship = max (single_relationships , key = lambda r : r .changed_at )
334- last_changed_at = last_changed_relatonship .changed_at
343+ last_changed_relationship = max (single_relationships , key = lambda r : r .changed_at )
344+ last_changed_at = last_changed_relationship .changed_at
335345 action = DiffAction .UPDATED
336346 if last_changed_at < from_time :
337347 action = DiffAction .UNCHANGED
@@ -358,9 +368,19 @@ class DiffNodeIntermediate(TrackedStatusUpdates):
358368 relationships_by_name : dict [str , DiffRelationshipIntermediate ] = field (default_factory = dict )
359369
360370 def to_diff_node (self , from_time : Timestamp ) -> DiffNode :
361- attributes = [attr .to_diff_attribute (from_time = from_time ) for attr in self .attributes_by_name .values ()]
362- relationships = [rel .to_diff_relationship (from_time = from_time ) for rel in self .relationships_by_name .values ()]
371+ attributes = []
372+ for attr in self .attributes_by_name .values ():
373+ diff_attr = attr .to_diff_attribute (from_time = from_time )
374+ if diff_attr .action is not DiffAction .UNCHANGED :
375+ attributes .append (diff_attr )
376+ relationships = []
377+ for rel in self .relationships_by_name .values ():
378+ diff_rel = rel .to_diff_relationship (from_time = from_time )
379+ if diff_rel .action is not DiffAction .UNCHANGED :
380+ relationships .append (diff_rel )
363381 action , changed_at = self .get_action_and_timestamp (from_time = from_time )
382+ if not attributes and not relationships :
383+ action = DiffAction .UNCHANGED
364384 return DiffNode (
365385 uuid = self .uuid ,
366386 kind = self .kind ,
@@ -384,8 +404,11 @@ class DiffRootIntermediate:
384404 def to_diff_root (self , from_time : Timestamp , to_time : Timestamp ) -> DiffRoot :
385405 nodes = []
386406 for node in self .nodes_by_id .values ():
387- if not node .is_empty :
388- nodes .append (node .to_diff_node (from_time = from_time ))
407+ if node .is_empty :
408+ continue
409+ diff_node = node .to_diff_node (from_time = from_time )
410+ if diff_node .action is not DiffAction .UNCHANGED :
411+ nodes .append (diff_node )
389412 return DiffRoot (uuid = self .uuid , branch = self .branch , nodes = nodes , from_time = from_time , to_time = to_time )
390413
391414
@@ -403,10 +426,11 @@ def __init__(
403426 self .schema_manager = schema_manager
404427 self .from_time = from_time
405428 self .to_time = to_time or Timestamp ()
429+ # if this diff is for the base branch, use from_time b/c create_time would be too much
406430 if diff_branch .name == base_branch .name :
407- self .diff_branch_create_time = from_time
431+ self .diff_branched_from_time = from_time
408432 else :
409- self .diff_branch_create_time = Timestamp (diff_branch .get_created_at ())
433+ self .diff_branched_from_time = Timestamp (diff_branch .get_branched_from ())
410434 self ._diff_root_by_branch : dict [str , DiffRootIntermediate ] = {}
411435 self ._final_diff_root_by_branch : dict [str , DiffRoot ] = {}
412436
@@ -610,19 +634,19 @@ def _remove_empty_base_diff_root(self) -> None:
610634 ordered_diff_values = property_diff .get_ordered_values_asc ()
611635 if not ordered_diff_values :
612636 continue
613- if ordered_diff_values [- 1 ].changed_at >= self .diff_branch_create_time :
637+ if ordered_diff_values [- 1 ].changed_at >= self .diff_branched_from_time :
614638 return
615639 for relationship_diff in node_diff .relationships_by_name .values ():
616640 for diff_relationship_property_list in relationship_diff .properties_by_db_id .values ():
617641 for diff_relationship_property in diff_relationship_property_list :
618- if diff_relationship_property .changed_at >= self .diff_branch_create_time :
642+ if diff_relationship_property .changed_at >= self .diff_branched_from_time :
619643 return
620644 del self ._diff_root_by_branch [self .base_branch_name ]
621645
622646 def _finalize (self ) -> None :
623647 for branch , diff_root_intermediate in self ._diff_root_by_branch .items ():
624648 if branch == self .base_branch_name :
625- from_time = self .diff_branch_create_time
649+ from_time = self .diff_branched_from_time
626650 else :
627651 from_time = self .from_time
628652 self ._final_diff_root_by_branch [branch ] = diff_root_intermediate .to_diff_root (
0 commit comments