<?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>Ugly Code! &#187; queries</title>
	<atom:link href="http://uglycode.com/tag/queries/feed/" rel="self" type="application/rss+xml" />
	<link>http://uglycode.com</link>
	<description>c0ding is seriose busines!!!!1</description>
	<lastBuildDate>Thu, 15 Jul 2010 20:03:01 +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>OCD code?</title>
		<link>http://uglycode.com/2008/10/ocd-code/</link>
		<comments>http://uglycode.com/2008/10/ocd-code/#comments</comments>
		<pubDate>Sun, 26 Oct 2008 20:51:09 +0000</pubDate>
		<dc:creator>analytik</dc:creator>
				<category><![CDATA[optimization]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[queries]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://uglycode.com/?p=10</guid>
		<description><![CDATA[
if &#40;!empty&#40;fetchResult&#40;&#41;&#41; and isObject&#40;fetchResult&#40;&#41;&#41; and is_a&#40;fetchResult&#40;&#41;, &#34;objectType&#34;&#41;&#41; &#123;
  $result = fetchResult&#40;&#41;;
  doSomethingElse&#40;&#41;;
&#125;
elseif &#40;isObject&#40;fetchResult&#40;&#41;&#41; &#123;
  $result = fetchResult&#40;&#41;;
&#125;

I think the guy who wrote it was slightly OCD. And he definitely forgot that fetchResult() fetches results&#8230; from the database.
After optimizing aforementioned code and singleton-ifying the fetchResult(), number of queries made in one pageload went [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span>fetchResult<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> and isObject<span style="color: #009900;">&#40;</span>fetchResult<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> and <span style="color: #990000;">is_a</span><span style="color: #009900;">&#40;</span>fetchResult<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;objectType&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> fetchResult<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  doSomethingElse<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>isObject<span style="color: #009900;">&#40;</span>fetchResult<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> fetchResult<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I think the guy who wrote it was slightly OCD. And he definitely forgot that fetchResult() fetches results&#8230; from the database.</p>
<p>After optimizing aforementioned code and singleton-ifying the fetchResult(), number of queries made in one pageload went down to 300 from 800. Our code is just <em>awesome</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://uglycode.com/2008/10/ocd-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
