-2 seconds on query baby

This commit is contained in:
2024-07-16 04:36:56 +03:00
parent 422b24f52d
commit bcb7cd66ee

View File

@@ -62,9 +62,6 @@ async def get_stocks_data(
.select_from(
SupplierProduct
)
.join(
Product
)
.where(
SupplierProduct.supplier_id.in_(supplier_ids)
)
@@ -171,21 +168,15 @@ async def get_stocks_data(
in_block_subquery = (
select(
Product.id.label('product_id'),
SupplierProduct.product_id.label('product_id'),
func.min(SupplierProduct.in_block).label('in_block_value')
)
.select_from(
Product
)
.join(
SupplierProduct
)
.where(
SupplierProduct.supplier_id.in_(supplier_ids),
(SupplierProduct.supplier_stock - SupplierProduct.sold_today) > 0
)
.group_by(
Product.id
SupplierProduct.product_id
)
.subquery()
)
@@ -291,7 +282,11 @@ async def get_stocks_data(
slaves_stock_subquery.c.product_id == MarketplaceProduct.product_id
)
)
print(stmt.compile(compile_kwargs={
'literal_binds': True
}))
result = await session.execute(stmt)
marketplace_products = result.all()
response: List[StockData] = []
for (marketplace_product,