Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Optimize queries and remove redundant data fetching

Marcin Gębala31266461e907
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.py
index dda33157e0..5900613b6b 100644
--- a/saleor/graphql/api.py
+++ b/saleor/graphql/api.py
@@ -220,7 +220,9 @@ class Viewer(graphene.ObjectType):
debug = graphene.Field(DjangoDebug, name='__debug')
def resolve_category(self, args, context, info):
- return get_object_or_none(Category, pk=args.get('pk'))
+ category = get_object_or_none(
+ Category.objects.prefetch_related('children'), pk=args.get('pk'))
+ return category
def resolve_attributes(self, args, context, info):
category_pk = args.get('category_pk')
diff --git a/saleor/static/js/components/categoryPage/CategoryFilter.js b/saleor/static/js/components/categoryPage/CategoryFilter.js
index 7449fd8049..88f0b9ab81 100644
--- a/saleor/static/js/components/categoryPage/CategoryFilter.js
+++ b/saleor/static/js/components/categoryPage/CategoryFilter.js
@@ -8,15 +8,16 @@ export default class CategoryFilter extends Component {
render() {
const { category } = this.props;
+ const parent = category.ancestors ? category.ancestors[category.ancestors.length - 1] : null;
return (
<div className="categories">
<h2><strong>{category.name}</strong></h2>
- {category.parent ? (
+ {parent ? (
<div className="parents">
<i className="fa fa-arrow-left" aria-hidden="true"></i>
- <a href={category.parent.url}>See all {category.parent.name}</a>
+ <a href={parent.url}>See all {parent.name}</a>
</div>
) : (null)}
<ul className={category.parent ? ("childs") : ("childs no-parent")}>
diff --git a/saleor/static/js/components/categoryPage/CategoryPage.js b/saleor/static/js/components/categoryPage/CategoryPage.js
index a176d63073..f4aeea0ea0 100644
--- a/saleor/static/js/components/categoryPage/CategoryPage.js
+++ b/saleor/static/js/components/categoryPage/CategoryPage.js
@@ -196,11 +196,6 @@ export default Relay.createContainer(CategoryPage, {
pk
name
url
- parent {
- id
- name,
- url
- }
ancestors {
name
pk
@@ -211,12 +206,6 @@ export default Relay.createContainer(CategoryPage, {
pk
url
slug
- children {
- name
- pk
- url
- slug
- }
}
products (first: $count, attributes: $attributesFilter, priceGte: $minPrice, priceLte: $maxPrice, orderBy: $sortBy) {
${ProductList.getFragment('products')}