<?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>Jory&#039;s blog &#187; Random blah</title>
	<atom:link href="http://blog.jorygeerts.nl/category/rand/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jorygeerts.nl</link>
	<description>Just another WordPress weblog, or something like that</description>
	<lastBuildDate>Tue, 09 Aug 2011 19:40:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How keeping code in the right layer saved a website</title>
		<link>http://blog.jorygeerts.nl/2010/10/how-keeping-code-in-the-right-layer-saved-a-website/</link>
		<comments>http://blog.jorygeerts.nl/2010/10/how-keeping-code-in-the-right-layer-saved-a-website/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 19:53:23 +0000</pubDate>
		<dc:creator>Jory</dc:creator>
				<category><![CDATA[Random blah]]></category>

		<guid isPermaLink="false">http://blog.jorygeerts.com/?p=92</guid>
		<description><![CDATA[At my job at e-sites, one of the projects I worked on was the new Sport 1 website. The website went live yesterday morning. About 20 minutes later, I was asked to look at why it was so slow. For &#8230; <a href="http://blog.jorygeerts.nl/2010/10/how-keeping-code-in-the-right-layer-saved-a-website/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>At my job at <a href="http://www.e-sites.nl">e-sites</a>, one of the projects I worked on was the <a href="http://www.sport1.nl/">new Sport 1 website</a>. The website went live yesterday morning. About 20 minutes later, I was asked to look at why it was so slow.</p>
<p>For the website, we had a layered setup. In our &#8216;domain layer&#8217;, we had <em>models</em> and <em>entities</em>, where a <em>model</em> understood how to work with an <em>entity</em>. So, say I want all the news articles for a specific sport, I can do this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$aNewsArticles</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$oNewsModel</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getForSport<span style="color: #009900;">&#40;</span><span style="color: #000088;">$iSportId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Where <em>$oNewsModel</em> is an instance of our <em>news model</em>. After the call, <em>$aNewsArticles</em> would be an array, containing instances of our <em>news entity</em> class. Simple, right?</p>
<p>Well, apparently not. Since I setup the groundwork for the project and (basically) then went on vacation with little time to explain it to others, this is what I ran into:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">Class</span> NewsModel <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getForSport<span style="color: #009900;">&#40;</span><span style="color: #000088;">$iSportId</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    <span style="color: #000088;">$aArticles</span> <span style="color: #339933;">=</span> query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT newsId from news where sportId = <span style="color: #009933; font-weight: bold;">%d</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$iSportId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #000088;">$aArticleList</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$aArticles</span> <span style="color: #b1b100;">AS</span> <span style="color: #000088;">$aArticle</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	        <span style="color: #000088;">$aArticleList</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NewsEntity<span style="color: #009900;">&#40;</span><span style="color: #000088;">$aArticle</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'newsId'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span>
	    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$aArticleList</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Do you see where this is going? Yes, thats where</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">Class</span> NewsEntity <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$iArticleId</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    <span style="color: #000088;">$aData</span> <span style="color: #339933;">=</span> query<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * from news where newsId = <span style="color: #009933; font-weight: bold;">%d</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$iSportId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>iId <span style="color: #339933;">=</span> <span style="color: #000088;">$aData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'newsId'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	    <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>sTitle <span style="color: #339933;">=</span> <span style="color: #000088;">$aData</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'newsTitle'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	    <span style="color: #666666; font-style: italic;">/* ..... */</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Taking into account that on the frontpage we a bunch of lists with a total of 80 articles that where all retreived the same way, we where executing at least 80 queries to much. And all that, just because somebody put the query in the wrong place.</p>
<p>In the end, it was a fairly easy fix, but it shouldn&#8217;t have been done this way in the first place. Now, I understand how this would have happened. Somebody had to do the first thing with news and, in that particular case, knew the ID of the news-item, since it was part of the URL. Well, if you already know the ID, whats easier then this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$oNewsItem</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NewsEntity<span style="color: #009900;">&#40;</span><span style="color: #000088;">$iId</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Yea, that must be the easiest way to make that work. Feed the ID into the entity object and have that get the rest. And then, when you need a bunch of those objects, well, just selecting the IDs of the items you need and creating new objects, which then get the rest of the data, thats pretty easy, too. To bad its also not so fun for the database server.</p>
<p>So now we know how it happened, how do we make sure it doesn&#8217;t happen again? Obviously, making sure everybody has the same idea of what should go where is a (good) start. Ideally, there would be time to write some documentation, and you&#8217;d be able to oversee (and participate in) the further development, meaning you can put a stop to something while its happening instead of after the website went live. But, like I said, I was going on vacation, so I did neither. <img src='http://blog.jorygeerts.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jorygeerts.nl/2010/10/how-keeping-code-in-the-right-layer-saved-a-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keep Europe free of software patents</title>
		<link>http://blog.jorygeerts.nl/2009/02/keep-europe-free-of-software-patents/</link>
		<comments>http://blog.jorygeerts.nl/2009/02/keep-europe-free-of-software-patents/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 16:47:49 +0000</pubDate>
		<dc:creator>Jory</dc:creator>
				<category><![CDATA[Random blah]]></category>

		<guid isPermaLink="false">http://blog.jorygeerts.com/?p=48</guid>
		<description><![CDATA[Software patents suck. Sign the peption, maybe the politicians get it. &#60;/link-spam&#62;]]></description>
			<content:encoded><![CDATA[<p><a href="http://stopsoftwarepatents.eu/">Software patents suck. Sign the peption, maybe the politicians get it.</a> &lt;/link-spam&gt;<a href="http://stopsoftwarepatents.eu/"><br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jorygeerts.nl/2009/02/keep-europe-free-of-software-patents/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Statistics</title>
		<link>http://blog.jorygeerts.nl/2007/01/statistics/</link>
		<comments>http://blog.jorygeerts.nl/2007/01/statistics/#comments</comments>
		<pubDate>Mon, 29 Jan 2007 20:39:40 +0000</pubDate>
		<dc:creator>Jory</dc:creator>
				<category><![CDATA[Random blah]]></category>

		<guid isPermaLink="false">http://blog.jorygeerts.com/2007/01/29/statistics/</guid>
		<description><![CDATA[I just overheard my sister make a comment about some commercials. She said it didn&#8217;t make sence that you should eat 2 pieces of fruit and 200G of vegetables (commercial from the health department in our govermen), yet 90% of &#8230; <a href="http://blog.jorygeerts.nl/2007/01/statistics/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just overheard my sister make a comment about some commercials. She said it didn&#8217;t make sence that you should eat 2 pieces of fruit and 200G of vegetables (commercial from the health department in our govermen), yet 90% of all teethrot is caused by fruits (according to a toothpaste producer).<br />
This got me thinking. Why do we rely on statistics this much? I know I don&#8217;t trust them unless I can see information on how they where gathered, but when I look around me, I think thats just me being paranoid. (Or other people being stupid. <img src='http://blog.jorygeerts.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ) When I look around me, I don&#8217;t just see people take <em>interpetations of</em> statistics as facts, but just about anything else that looks in any way &#8220;official&#8221; or has enough impressive words in it. Ad to that the increasing ease of making a source of information look like it can be trusted to be objective and honest, and I worry. Because, if you can get half the population beleave that they need to eat fruit to be healthy, and use product X with its &#8220;unique&#8221; substance to stop the teethrot caused by that fruit, who knows what else you can do?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jorygeerts.nl/2007/01/statistics/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Buurgenootschap &#8216;t Bergske</title>
		<link>http://blog.jorygeerts.nl/2007/01/buurgenootschap-t-bergske/</link>
		<comments>http://blog.jorygeerts.nl/2007/01/buurgenootschap-t-bergske/#comments</comments>
		<pubDate>Mon, 22 Jan 2007 21:31:34 +0000</pubDate>
		<dc:creator>Jory</dc:creator>
				<category><![CDATA[Random blah]]></category>

		<guid isPermaLink="false">http://blog.jorygeerts.com/2007/01/22/buurgenootschap-t-bergske/</guid>
		<description><![CDATA[Just ignore this post, ok? For our local community, Buurschap &#8216;t Bergske, I made a website. Its basically a mix of WordPress and Plogger, with some custom coding to make them blend together. Most work actually went into finding out &#8230; <a href="http://blog.jorygeerts.nl/2007/01/buurgenootschap-t-bergske/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><!--nosyndicate--><br />
Just ignore this post, ok?<span id="more-20"></span></p>
<plug syndicate="nosyndicate">
For our local community, <a href="http://t-bergske.nl/">Buurschap &#8216;t Bergske</a>, I made <a href="http://t-bergske.nl/">a website</a>. Its basically a mix of <a href="http://wordpress.org/">WordPress</a> and <a href="http://plogger.org/">Plogger</a>, with some custom coding to make them blend together. Most work actually went into finding out how the backend of WordPress works (I didn&#8217;t need to modify much about Plogger) and I still don&#8217;t really have a clue. <img src='http://blog.jorygeerts.nl/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  I&#8217;m fairly happy about how <a href="http://t-bergske.nl/">the website for Buurgenootschap &#8216;t Bergske</a> turned out. The design needs some tweaking, and I need to get rid of / translate some of the outputs, but thats a worry for later. (read: That&#8217;ll never happen..)</plus>
<p><explaination>Ok, so non of you care.. the thing is, this place is at least known to search engines, the new website isn&#8217;t. So, now it is. <img src='http://blog.jorygeerts.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </explaination></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jorygeerts.nl/2007/01/buurgenootschap-t-bergske/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

