Skip to content

Commit 0429eaf

Browse files
authored
Merge pull request #7175 from escattone/reduce-product-support-queries
improve performance of two product support methods
2 parents edc7554 + 585c212 commit 0429eaf

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

kitsune/products/models.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,18 @@ def image_alternate_url(self):
9797
@property
9898
def has_ticketing_support(self):
9999
"""Return boolean if a product has Zendesk ticketing support"""
100-
try:
101-
config = self.support_configs.get(is_active=True)
102-
except ProductSupportConfig.DoesNotExist:
103-
return False
104-
else:
105-
return config.enable_zendesk_support
100+
return self.support_configs.filter(
101+
is_active=True,
102+
zendesk_config__isnull=False,
103+
).exists()
106104

107105
def questions_enabled(self, locale):
108106
"""Check if product has an active public forum in the given locale."""
109-
try:
110-
config = self.support_configs.get(is_active=True)
111-
except ProductSupportConfig.DoesNotExist:
112-
return False
113-
114-
return (
115-
config.forum_config
116-
and config.forum_config.is_active
117-
and config.forum_config.enabled_locales.filter(locale=locale).exists()
118-
)
107+
return self.support_configs.filter(
108+
is_active=True,
109+
forum_config__is_active=True,
110+
forum_config__enabled_locales__locale=locale,
111+
).exists()
119112

120113
def get_absolute_url(self):
121114
return reverse("products.product", kwargs={"slug": self.slug})

0 commit comments

Comments
 (0)