Skip to content

Commit 5146830

Browse files
endpoint: optimize __eq__ via product_id
1 parent e1cc7d4 commit 5146830

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

dojo/models.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,14 +1799,11 @@ def __hash__(self):
17991799

18001800
def __eq__(self, other):
18011801
if isinstance(other, Endpoint):
1802-
# Check if the contents of the endpoint match
18031802
contents_match = str(self) == str(other)
1804-
# Determine if products should be used in the equation
1805-
if self.product is not None and other.product is not None:
1806-
# Check if the products are the same
1807-
products_match = (self.product) == other.product
1808-
# Check if the contents match
1809-
return products_match and contents_match
1803+
# Use product_id (cached integer) instead of self.product to avoid
1804+
# triggering a FK lookup on every comparison inside NestedObjects.add_edge.
1805+
if self.product_id is not None and other.product_id is not None:
1806+
return self.product_id == other.product_id and contents_match
18101807
return contents_match
18111808

18121809
return NotImplemented

0 commit comments

Comments
 (0)