Wednesday, January 20, 2010

Bring in the APIs!

I am finally opening up my big project. Not pretty yet but it is functional so far. It has passed through months of testing and sobbing and pounding of head on monitor. But here it is. I'd love to see if you can break it.

What does it do? It combines shopping APIs from all over the place. eBay, Amazon, LinkShare, Commission Junction, Valore and many others to give the biggest internet comparison shopping site around. Is it slow? Not really. That took the most work but I did it with ColdFusion 8 and cfthread.

First thing I did was to build the API search functions into a CFC. Make the cfc an application object since it is used by everybody all the time. 1 function for each API. When run in sequence it was taking up to 1 minute to get any results. What was I to do?

Okay, I did threads. Each api call is a thread. This also helped if there was an error along the way in any of them it wouldn't jam up the whole thing. So this got results in around 15 seconds. What I did to take up the time was put an intermediate page in. You enter your search and you go to this "doing search" page where you see advertisements for other products. The searches themselves are actually happening in an iFrame that is 1px by 1px. When it is done loading it redirects the parent page to the results page.

BUT where are the results? To keep from jamming up my server memory I decided to jam up my database instead. Everybody who comes on the site gets their own temp table that holds the results of their searches. This way subsequent searches to narrow down the results are faster and easier. Of course this leaves the problem much like abandoned shopping carts. No biggy tho. Same solution. On session end the table is dropped. If that doesn't get it I have a scheduled task that runs every hour that clears out any tables that are over 2 hours old, which just happens to be the same as the session time out.  I seriously doubt anybody is going to be searching on my site for over 2 hours. But if they are they will get a new table because that is the first check I do in the onRequest function.

Anyway, it is still a work in progress but it is doing great so far. It is also the foundation for my entry into the PayPal new Advanced Payment API contest. Wish me luck on that. I have my application submitted for approval.

The site of my most awesome project? http://www.donomall.com/

Labels: , , , ,