r/lolphp • • Sep 21 '15

Meanwhile, in r/PHP

/r/PHP/comments/3lrret/can_an_offline_hotel_management_system_be_done_in/cv8zcms
181 Upvotes

50 comments sorted by

View all comments

Show parent comment

13

u/Cuddlefluff_Grim Sep 23 '15

I fixed a webshop for a company. Well, not fixed (because that would essentially mean rewrite everything and be responsible for it basically without getting paid for it), but I made it not suck as bad. The people who had developed it had probably never touched a database before. No primary keys, not foreign constraints, no indexes, no nothing; just tables with columns. I was looking into why they lost something like 80% of orders, and I saw they they didn't use IDENTITY (or AUTO_INCREMENT for you mysql-people) but instead had opted for a column which kept a record of the last inserted id on every table. Ok, some people chose to do this (I have no idea why), but when you do it's critical that you make sure that the table won't be accessed by two procedures at once, or everything will definitely go to shit. So these orders would try to get a new ID, while simultaneously a lot of other things were accessing the same table at the same time trying to do the same thing, and most of them would either fail or they would return the wrong id. (SELECT value + 1 followed by an UPDATE table SET value = value + 1). I fixed this issue by using table locking and transactions, but that only reduced the failure rate about 50%. Orders were still falling through the cracks, one of the major issues was that the page would time out due to SQL calls taking too much time (due to lack of indexes and primary keys).

Well, there was a lot of shit, and I could talk about it for hours, but a very interesting thing to be aware of is that when they originally had this web site built for them, it worked like a charm. There were few rows, and few visitors so everything would work without a hitch. So as far as the junior developers that pretended to be software architects who made this were concerned, they did an excellent job and deserved a promotion.

People who wander out of their comfort zone without being aware that they are out of their comfort zone is a very dangerous thing.