1

I am using static HTML/C# methods for a company website with 300,000 users.

BACKGROUND:

I have an html page on my website where a user can view extensive reports (20,000+ records). But it is all paged/sorted server-side (most users will be viewing something like 151-200 of 20,000 records). If a user selects a report that calls the API /api/ViewAllCustomers, a query is run and the entire results are cached for 5 minutes using a key like "userNumber + filters + reportName". When a user changes the page size of the report, the same report will be pulled from cache, but return a different number of records.

ISSUE:

When a user clicks a "Download to Excel" button, I need the entire report (20,000+ records) to download to an excel file for a user WITHOUT changing the current report they are viewing (could be records 151-200 of 20,000 records). It seems like there a couple options. I can use the same method with an overload parameter on my API of "bool DownloadToExcel = false" and then save the file on the server and return a path to that URL. OR I can build an invisible table client side and download it from there. It seems like when tens of thousands of people are requesting to "Download to Excel", the server would be flooded with files.

Should I cache these excel files server-side for a few minutes and give the user a path to the file? Or should I build build the table client-side, and generate the Excel file from there?

Jordan B
  • 109
  • 8

1 Answers1

1

The easiest way may be opening the excel report in a new tab on browser. if you use ajax call, response processing come into concern. two simple ways:

<a href="/api/ViewAllCustomers" target="_blank">Download The Report</a>

the other way when you need to post something to server:

<form method="post" action="/api/ViewAllCustomers" target="_blank">
   <input name="someProperty" value="someValue" type="hidden" />
   <input type="submit" value="Download the report" />
</form>

also you can put an iframe named 'downloadTarget' and change the 'target' property of the above form to 'downloadTarget'

<iframe name="downloadTarget" style="width: 0; height: 0; border: 0;"></iframe>

<form method="post" action="/api/ViewAllCustomers" target="downloadTarget">
    <input name="someProperty" value="someValue" type="hidden" />
    <input type="submit" value="Download the report" />
</form>


BUT ABOUT CACHING because the filters change the result excel file, you have two or more options:

1: don't cache the result file. because you have different reports according to the filters

2: don't save it on hard disk on server. if your file size is high, this download interrupts may be your issue.

3: cache files with a key like "reportType-filter1-filter2" that filters are sorted alphabetically.

Reza Bayat
  • 393
  • 2
  • 5