currency graphing

Over the weekend I did some long-awaited work on my exchange rate graph application.

The most obvious change is that you can now choose a range of dates rather than always getting all the data. I decided to have just a fixed set of ranges to choose from, since it does what most people should want, and is simpler to code and present.

Of course there were far more changes behind the scenes.

Firstly I did some rewriting to tidy up the Javascript using the JQuery library. When I first wrote this application, I was only just learning about Rails and, so it had a mess of generated Javascript thrown into the page. I’ve now removed that so there is a cleaner design, which made it easier to do the other changes1.

Next I realised that the code was making far more database queries that it needed to, and this was causing it to crash out sometimes in Dreamhost’s restricted resource environment. With a small database refactoring and some rewriting of the controller code I’ve reduced it to n + 1 queries2 now (and could probably go to 1 with some more work, but at the cost of a more complicated query). It is a useful lesson in Rails design though – it makes it very easy to make method calls that run extra database queries if you don’t think about it. Anyway, it seems more responsive now.

Lastly, I did what I should have done in the first place, and made it so it can be used without Javascript turned on. It uses a form that needs to be submitted, so the behaviour doesn’t seem so smooth, but it is usable.

Next up I should try and make the page look a bit nicer!

1 I must remember to switch to the compressed JQuery files.

2 n = number of currencies shown in the graph.

One Comment

  1. Posted April 17, 2007 at 3:19 am | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *