Skip to content

Commit

Permalink
refactor: Enhance get_products with eager loading
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-lymar committed Jun 15, 2024
1 parent 0c2586f commit 49b1e73
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 3 additions & 2 deletions clients/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

# Базовый класс для получения данных по записям клиентов
class ClientAPIView(generics.ListCreateAPIView[Client]):
queryset = Client.objects.select_related("director_position", "destination_city",
"railway_station").all()
queryset = Client.objects.select_related(
"director_position", "destination_city", "railway_station"
).all()
serializer_class = ClientSerializer
permission_classes = (IsAuthenticated,)

Expand Down
6 changes: 1 addition & 5 deletions makedoc/data_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ def get_products(validated_data):
results = []
cached_goods = cache.get("goods_list")
if cached_goods is None:
try:
cached_goods = list(Product.objects.all())
cache.set("goods_list", cached_goods, 1800)
except Exception:
cached_goods = list(Product.objects.all())
cached_goods = Product.objects.select_related("flour_name", "brand", "package").all()
for item in products_data:
product_id = item.get("product_id")
product_quantity = item.get("quantity")
Expand Down

0 comments on commit 49b1e73

Please sign in to comment.