<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Data-Diggers.com &#187; store credit</title>
	<atom:link href="http://www.data-diggers.com/index.php/tag/store-credit/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.data-diggers.com</link>
	<description>Zen Cart Optimization, Performance and A/B Split Testing Modules for Zen Cart</description>
	<lastBuildDate>Mon, 24 May 2010 18:56:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Performance issues with Store Credit Module in admin area</title>
		<link>http://www.data-diggers.com/index.php/2009/06/performance-issues-with-store-credit-module-in-admin-area/</link>
		<comments>http://www.data-diggers.com/index.php/2009/06/performance-issues-with-store-credit-module-in-admin-area/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 13:34:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[store credit]]></category>
		<category><![CDATA[Zen Cart]]></category>

		<guid isPermaLink="false">http://www.data-diggers.eu/?p=55</guid>
		<description><![CDATA[
			
				
			
		
Store Credit is great module, unfortunately it&#8217;s preety inefecient in some places. For example, on every page request of admin/store_credit.php whole customers table is read, and for each customer additional SELECT and UPDATE query is executed to calculate and update pending points, even if the customer does not have any pending points!
It&#8217;s not a big deal [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.data-diggers.com%2Findex.php%2F2009%2F06%2Fperformance-issues-with-store-credit-module-in-admin-area%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.data-diggers.com%2Findex.php%2F2009%2F06%2Fperformance-issues-with-store-credit-module-in-admin-area%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;"><strong>Store Credit</strong> is great module, unfortunately it&#8217;s preety inefecient in some places. For example, on every page request of<em> admin/store_credit.php</em> whole customers table is read, and for each customer additional SELECT and UPDATE query is executed to calculate and update pending points, even if the customer does not have any pending points!</p>
<p style="text-align: justify;">It&#8217;s not a big deal when You have up to 1000 customers, but when there are more then 100 000 customers page loads in 30 seconds (store_credit.php executes over 2 x customer count,  or in this example over 200 000 queries on each request).</p>
<p style="text-align: justify;">To address that, change following code in admin/store_credit.php:</p>
<div style="text-align: justify;">
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="kw2">function</span> store_pending_rewards<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">global</span> <span class="re0">$db</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$customers</span> <span class="sy0">=</span> <span class="re0">$db</span><span class="sy0">-&gt;</span><span class="me1">Execute</span><span class="br0">&#40;</span><span class="st0">&quot;SELECT customers_id FROM &quot;</span> <span class="sy0">.</span> TABLE_CUSTOMERS <span class="sy0">.</span> <span class="st0">&quot; ORDER BY customers_id ASC&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="re0">$customers</span><span class="sy0">-&gt;</span><span class="me1">EOF</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$customers_id</span> <span class="sy0">=</span> <span class="re0">$customers</span><span class="sy0">-&gt;</span><span class="me1">fields</span><span class="br0">&#91;</span><span class="st_h">&#8216;customers_id&#8217;</span><span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$pending_rewards</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">get_pending_rewards</span><span class="br0">&#40;</span><span class="re0">$customers_id</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$db</span><span class="sy0">-&gt;</span><span class="me1">Execute</span><span class="br0">&#40;</span><span class="st0">&quot;UPDATE &quot;</span> <span class="sy0">.</span> TABLE_STORE_CREDIT <span class="sy0">.</span> <span class="st0">&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SET pending = &quot;</span> <span class="sy0">.</span> <span class="re0">$pending_rewards</span> <span class="sy0">.</span> <span class="st0">&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE customers_id = &quot;</span> <span class="sy0">.</span> <span class="re0">$customers_id</span> <span class="sy0">.</span> <span class="st0">&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LIMIT 1&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$customers</span><span class="sy0">-&gt;</span><span class="me1">MoveNext</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
</div>
<p style="text-align: justify;">to:</p>
<div style="text-align: justify;">
<div class="codesnip-container" >
<div class="php codesnip" style="font-family:monospace;"><span class="kw2">function</span> store_pending_rewards<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">global</span> <span class="re0">$db</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$customers</span> <span class="sy0">=</span> <span class="re0">$db</span><span class="sy0">-&gt;</span><span class="me1">Execute</span><span class="br0">&#40;</span><span class="st0">&quot;SELECT DISTINCT customers_id FROM &quot;</span> <span class="sy0">.</span> TABLE_SC_REWARD_POINT_LOGS <span class="sy0">.</span> <span class="st0">&quot; ORDER BY customers_id ASC&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="re0">$customers</span><span class="sy0">-&gt;</span><span class="me1">EOF</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$customers_id</span> <span class="sy0">=</span> <span class="re0">$customers</span><span class="sy0">-&gt;</span><span class="me1">fields</span><span class="br0">&#91;</span><span class="st_h">&#8216;customers_id&#8217;</span><span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$pending_rewards</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">get_pending_rewards</span><span class="br0">&#40;</span><span class="re0">$customers_id</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$pending_rewards</span> <span class="sy0">==</span> 0<span class="sy0">.</span>0<span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="re0">$customers</span><span class="sy0">-&gt;</span><span class="me1">MoveNext</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="kw1">continue</span><span class="sy0">;</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$db</span><span class="sy0">-&gt;</span><span class="me1">Execute</span><span class="br0">&#40;</span><span class="st0">&quot;UPDATE &quot;</span> <span class="sy0">.</span> TABLE_STORE_CREDIT <span class="sy0">.</span> <span class="st0">&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SET pending = &quot;</span> <span class="sy0">.</span> <span class="re0">$pending_rewards</span> <span class="sy0">.</span> <span class="st0">&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE customers_id = &quot;</span> <span class="sy0">.</span> <span class="re0">$customers_id</span> <span class="sy0">.</span> <span class="st0">&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LIMIT 1&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$customers</span><span class="sy0">-&gt;</span><span class="me1">MoveNext</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
</div>
<p style="text-align: justify;">Thanks to that, only customers who actually have some pending points will be processed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.data-diggers.com/index.php/2009/06/performance-issues-with-store-credit-module-in-admin-area/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
