Thread image on threads view
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #8
RE: Thread image on threads view
It's discouraged as it puts unnecessary additional load on the forum.
http://stackoverflow.com/questions/94621...http://stackoverflow.com/questions/946214/one-sql-query-or-many
http://expressionengine.com/user_guide/d...http://expressionengine.com/user_guide/development/guidelines/performance.html#redunda

Arguably, this may not be a big issue if you don't have a lot of threads, and have very few visitors to your website (coupled with the fact that many MySQL servers are installed locally on the webserver), however it can be considered bad coding practice (and a hallmark of the n00b script kiddie).
It IS more of a problem if you have a remote SQL server (larger sites, or some shared hosting providers do this) as queries are slower due to increased latency.  And if you're a high traffic forum, this can generate significantly more load on the webserver <-> DB server network.

Simple example of an in-loop query:

PHP Code:
for(...) {
  $stuff = $db->fetch_array($db->simple_select(..., 'id='.$id));
}

More appropriate way:

PHP Code:
1
2
3
4
5
6
7
$query = $db->simple_select(..., 'id IN ('.$ids.')');
$data = array();
while($thing = $db->fetch_array($query))
  $data[$thing['id']] = $thing;
for(...) {
  $stuff = $data[$id];
}


Top one is easier and quicker to write, which is why a lot of people do it, despite it being "bad".


My Blog
10-23-2010 11:21 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
Thread image on threads view - 1master1 - 10-21-2010, 07:05 AM
RE: Thread image on threads view - RateU - 10-22-2010, 06:59 AM
RE: Thread image on threads view - Imran - 10-23-2010, 02:34 AM
RE: Thread image on threads view - leefish - 10-23-2010, 09:24 AM
RE: Thread image on threads view - ZiNgA BuRgA - 10-23-2010 11:21 AM
RE: Thread image on threads view - Imran - 10-23-2010, 08:41 PM
RE: Thread image on threads view - leefish - 10-24-2010, 04:08 AM

 Standard Tools
Forum Jump: