Question

I have a reporting and statistics application that displays various query results in a basic table format. At the bottom of the report results page is an option for the user to download the report result they are viewing to a CSV file. Similar functionality to online banking where you can view your bank transactions, and then optionally download the transactions history to csv.

What is the best practice method for doing this?

a. A download button that triggers the report query to be re-run and subsequently streamed to csv download file.

or

b. When query is first run and rendered in the view, the controller saves the report object in a session variable. The download button thus downloads to report object from the session variable versus having to re-run the query.

The benefit I see with option B is two-fold. 1. Report query does not have to be re-run, thus less load on database. 2. Report being downloaded from session variable is an exact match of the report displayed in the report result. With option a, the report downloaded could vary from the report being viewed if there are data updates between the time the report is viewed and the time the download link is triggered.

Are there any risks or drawbacks that I should consider if using the session variable approach?

Thanks in advance for any input or guidance.

Was it helpful?

Solution

You summed up the issues to be considered pretty nicely. In the end, it's a trade-off you will have to make. However, note that you cannot store resources such as MySQL results in $_SESSION (I'm not sure whether the "report object" you quoted is an actual object of a self-written report class or whether you were referring to the query result obtained from the database). I personally would prefer option B as it's guaranteed to not provide results differing from the ones visible in the application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top