I’ve got a query that collects a bunch of statistics from the database
and I want to display several graphs generated from that same data on
one page. (I’m using Gruff for the graphs.) I’ve only come up with two
basic ways to handle this:
-
Do the queries and the graph generation all in one controller action,
save the graphs to files and use plain old IMG tags to get them all on
the page. I’d rather not do this because I don’t want a mess of temp
files to deal with. -
Use separate controller actions for each graph, each of them using
send_data to output the graphs, and the view calls the actions in IMG
tags: . With this
method the query has to be repeated for each graph, which is a big
waste.
Any ideas on how to accomplish this without running the query several
times and without saving graphs to files?
The best thing I can think of right now is kind of a combination and
variation on both these ideas: in the initial action the data is
collected, the graphs are generated and stored temporarily as blobs in
the database, the ids of the blobs are passed to the view where they can
be used to call a graph retrieval action like . The get_graph action
can delete the records as soon as send_data is called so the images
aren’t hanging around after it’s done. Maybe an in-memory SQLite db
would be well suited for this task.
How does that idea sound? Any suggestions? Thanks.