From 5146830bb3dca99f210102a9cc76a12ab7bc4753 Mon Sep 17 00:00:00 2001 From: Valentijn Scholten Date: Mon, 4 May 2026 21:48:34 +0200 Subject: [PATCH] endpoint: optimize __eq__ via product_id --- dojo/models.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/dojo/models.py b/dojo/models.py index 153177bc20e..8cff7092ef6 100644 --- a/dojo/models.py +++ b/dojo/models.py @@ -1799,14 +1799,11 @@ def __hash__(self): def __eq__(self, other): if isinstance(other, Endpoint): - # Check if the contents of the endpoint match contents_match = str(self) == str(other) - # Determine if products should be used in the equation - if self.product is not None and other.product is not None: - # Check if the products are the same - products_match = (self.product) == other.product - # Check if the contents match - return products_match and contents_match + # Use product_id (cached integer) instead of self.product to avoid + # triggering a FK lookup on every comparison inside NestedObjects.add_edge. + if self.product_id is not None and other.product_id is not None: + return self.product_id == other.product_id and contents_match return contents_match return NotImplemented