Thursday, 13 January 2011

Coding WTF of the Week

I think I'll start a new segment for this blog, ala - DailyWTF.. hey,
I should submit this...

Task: Get a list of all securities that have prices.

Instead of doing a join between two tables (SECURITY, SECURITY_PRICE),
the developer did this

1. Get all securities.
2. Get all security prices.
3. Loop through all the securities.
4. Inside that loop, loop through all the prices.
5. Where price.securityId =, put them into the container class

Not too big a deal on dev database, but problematic on UAT database
which had 7000 securities and 1000 security prices.

Removing this code and replacing it with code that used a join,
brought down a method call from 50 seconds to 2 seconds.