a dumb programming mistake

I had a couple of dumb development mistakes come and bite me in the butt this week, and I thought I’d share them here – well, at least one for now.

Without going in to the type of data too much here – the specifics aren’t important – the system I’ve got needed to show a list of data to a user.  Initially we just showed all the data to the one user.  Later, we added other user types.  However, my controller code (MVC-style) simply defined different views to use based on user type, but never changed the query.  So, whether you were an admin, or an area user, or a distinct individual which should only have seen a few items from the list, your view was passed all of the data.  The views simply filtered out which ones to display during a loop.

Stupid?  Yes.  Noticeable?  Not at all.  I looked at this code yesterday and remember thinking at the time “yeah, I’ll go back and make this better later” – I was planning on overhauling the user/role system, and I’d fix it all later.  That never happened, and over the past couple years, this has become slower and slower.

Fast forwards to yesterday, and we had 80 processes each being handed *290,000* objects ina view, in most cases to filter and display, say, 60.  Even getting new updated software on the server today was a pain, because we were continually hitting loads of 40-70 (unix loads, 15 min avg of 60 was where we were at most of today).

This came to a head the past couple days because our usage patterns changed – user load spiked both because of timing in the month and the user base has grown.  It was a perfect storm, and I was caught in the middle.  The upside is that I found this major issue and it’s resolved.  The downside is that it took almost 2 days (mon and tue) because I was finding other things I thought were the culprits; they were issues, but had no major impact given the 800lb gorilla in the room.

Lessons learned?  I’m not immune to even basic stupid oversights.  The moment I saw this code, I knew the issue, but I’ve not looked at it in… 3 years?  There was no need to, so I never went back to audit for stupid code.  Perhaps I need to budget more time for stupidity audits?

Any major faux pas you care to share or admit to?

I'm currently working on a book for web freelancers, covering everything you need to know to get started or just get better. Want to stay updated? Sign up for my mailing list to get updates when the book is ready to be released!

Web Developer Freelancing Handbook

Leave a Reply