Hi All,
I had about 400 orders in the space of a couple of hours last night.
This is of course great - but..... it could have been hundreds more.
The site slowed to a crawl & lots of people just couldn't be bothered to wait.
I asked the host (ChannelAdvisor) for help & they tell me that a DB query was causing the slowdown.
Here's the offending xmlpackage :-
HTML Code:
<?xml version="1.0" standalone="yes" ?>
<package version="2.1" displayname="subcat-top3.xml.config" debug="false" includeentityhelper="false">
<!-- ###################################################################################################### -->
<!-- Copyright AspDotNetStorefront.com, 1995-2008. All Rights Reserved. -->
<!-- http://www.aspdotnetstorefront.com -->
<!-- For details on this license please visit the product homepage at the URL above. -->
<!-- THE ABOVE NOTICE MUST REMAIN INTACT. -->
<!-- -->
<!-- ###################################################################################################### -->
<query name="Products" rowElementName="Product">
<sql>
<![CDATA[
SELECT DISTINCT TOP 3
s.ProductID,
s.NumSales,
s.Numpounds
FROM (
select ProductID, SUM(Quantity) AS NumSales, SUM(OrderedProductPrice) AS Numpounds
from dbo.Orders_ShoppingCart
sc
join [dbo].Orders o on sc.OrderNumber = o.OrderNumber and o.OrderDate >= dateadd(dy, -7, getdate())
group by ProductID
) s
join [dbo].Product p with (nolock) on s.productid = p.productid
WHERE p.Deleted = 0
and p.Published = 1
and p.ProductID in ( select ProductID from dbo.ProductCategory where CategoryID = @parent )
ORDER BY s.NumSales desc
]]>
</sql>
<queryparam paramname="@parent" paramtype="runtime" requestparamname="parent" sqlDataType="int" defvalue="0" validationpattern="" />
</query>
<query name="Products30" rowElementName="Product">
<sql>
<![CDATA[
SELECT DISTINCT TOP 3
s.ProductID,
s.NumSales,
s.Numpounds
FROM (
select ProductID, SUM(Quantity) AS NumSales, SUM(OrderedProductPrice) AS Numpounds
from dbo.Orders_ShoppingCart
sc
join [dbo].Orders o on sc.OrderNumber = o.OrderNumber and o.OrderDate >= dateadd(dy, -30, getdate())
group by ProductID
) s
join [dbo].Product p with (nolock) on s.productid = p.productid
WHERE p.Deleted = 0
and p.Published = 1
and p.ProductID in ( select ProductID from dbo.ProductCategory where CategoryID = @parent )
ORDER BY s.NumSales desc
]]>
</sql>
<queryparam paramname="@parent" paramtype="runtime" requestparamname="parent" sqlDataType="int" defvalue="0" validationpattern="" />
</query>
<query name="Products365" rowElementName="Product">
<sql>
<![CDATA[
SELECT DISTINCT TOP 3
s.ProductID,
s.NumSales,
s.Numpounds
FROM (
select ProductID, SUM(Quantity) AS NumSales, SUM(OrderedProductPrice) AS Numpounds
from dbo.Orders_ShoppingCart
sc
join [dbo].Orders o on sc.OrderNumber = o.OrderNumber and o.OrderDate >= dateadd(dy, -365, getdate())
group by ProductID
) s
join [dbo].Product p with (nolock) on s.productid = p.productid
WHERE p.Deleted = 0
and p.Published = 1
and p.ProductID in ( select ProductID from dbo.ProductCategory where CategoryID = @parent )
ORDER BY s.NumSales desc
]]>
</sql>
<queryparam paramname="@parent" paramtype="runtime" requestparamname="parent" sqlDataType="int" defvalue="0" validationpattern="" />
</query>
<query name="Category" rowElementName="Cat">
<sql>
<![CDATA[
SELECT CategoryID, Name from dbo.Category where CategoryID = @parent
]]>
</sql>
<queryparam paramname="@parent" paramtype="runtime" requestparamname="parent" sqlDataType="int" defvalue="0" validationpattern="" />
</query>
<PackageTransform>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:param name="CatName"><xsl:value-of select="/root/Category/Cat/Name" /></xsl:param>
<xsl:template match="/">
<xsl:param name="CatID"><xsl:value-of select="/root/QueryString/categoryid" /></xsl:param>
<xsl:choose>
<xsl:when test="count(/root/Products/Product) <'3'">
<xsl:choose>
<xsl:when test="count(/root/Products30/Product) <'3'">
<xsl:choose>
<xsl:when test="count(/root/Products365/Product) <'3'">
<div class="new-products">
<h2>Featured in <xsl:value-of select="$CatName" /></h2>
<div class="products-holder">
<xsl:value-of select="aspdnsf:XmlPackage('three.filler.random.xml.config', concat('parent=', $CatID))" disable-output-escaping="yes" />
</div>
</div>
</xsl:when>
<xsl:otherwise>
<div class="new-products">
<a class="see-more" href="e-topsellers.aspx?categoryid={/root/Category/Cat/CategoryID}">More Bestsellers</a>
<h2>Bestsellers in <xsl:value-of select="$CatName" /></h2>
<div class="products-holder">
<xsl:for-each select="/root/Products365/Product">
<xsl:variable name="prodid" select="ProductID" />
<xsl:value-of select="aspdnsf:XmlPackage('cat-best2.xml.config', concat('ProductID=', $prodid))" disable-output-escaping="yes" />
</xsl:for-each>
</div>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<div class="new-products">
<a class="see-more" href="e-topsellers.aspx?categoryid={/root/Category/Cat/CategoryID}">More Bestsellers</a>
<h2>Bestsellers in <xsl:value-of select="$CatName" /></h2>
<div class="products-holder">
<xsl:for-each select="/root/Products30/Product">
<xsl:variable name="prodid" select="ProductID" />
<xsl:value-of select="aspdnsf:XmlPackage('cat-best2.xml.config', concat('ProductID=', $prodid))" disable-output-escaping="yes" />
</xsl:for-each>
</div>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<div class="new-products">
<a class="see-more" href="e-topsellers.aspx?categoryid={/root/Category/Cat/CategoryID}">More Bestsellers</a>
<h2>Bestsellers in <xsl:value-of select="$CatName" /></h2>
<div class="products-holder">
<xsl:for-each select="/root/Products/Product">
<xsl:variable name="prodid" select="ProductID" />
<xsl:value-of select="aspdnsf:XmlPackage('cat-best2.xml.config', concat('ProductID=', $prodid))" disable-output-escaping="yes" />
</xsl:for-each>
</div>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
</PackageTransform>
</package>
Basically - it gets the 3 bestsellers for the past 7, 30 & 365 days.
It then calls another xmlpackage 3 time to display the bestsellers.
If there are not 3 entries in the past 7 days - it will switch to the last 30 days - if there are not 3 entries in the past 30 days it will switch to the last 365 days.
Channel advisor don't like it because it's "a nested select with a join that has a nested select & an additional join".
Is there a better (more DB efficient) way of achieving what I want?
I'd be grateful fo any input.
TTFN
BFG