MCPcopy Index your code
hub / github.com/diffgram/diffgram / detect_and_remove_collisions

Method detect_and_remove_collisions

shared/annotation.py:737–760  ·  view source on GitHub ↗
(self, instance_list)

Source from the content-addressed store, hash-verified

735
736 # Tested
737 def detect_and_remove_collisions(self, instance_list):
738 result = []
739 hashes_dict = {}
740 instance_list.sort(key = lambda item: (item.created_time is not None, item.created_time), reverse = True)
741
742 for inst in instance_list:
743
744 if inst.soft_delete is True:
745 result.append(inst)
746 continue
747
748 if hashes_dict.get(inst.hash) is None:
749 result.append(inst)
750 hashes_dict[inst.hash] = True
751 else:
752 # Collision detected, we keep the newest instance by created time (which was order sorted).
753 # So this one is just to be deleted and not added to results.
754 logger.warning(f"Collision detected on {inst.hash} instance id: {inst.id}")
755 logger.warning(f"hashes_dict: {hashes_dict}")
756 inst.soft_delete = True
757 inst.action_type = "from_collision"
758 self.session.add(inst)
759
760 return result
761
762 # Tested
763 def rehash_existing_instances(self, instance_list):

Calls 2

getMethod · 0.45
addMethod · 0.45

Tested by 1