I am implementing a search for a list of people in MVC ASP.Net Core 2.1. Initially, no records are present and the user enters some filters and gets people returned. Currently, the max amount of records is 400,000 and so if they return all records we end up sending 80 MB of data back to the ajax request which we then loop through. This can scale up quite a bit as the final size of the database will be larger then it is currently.
We first get the data with LINQ and then we return an enumerable which we send back as a JSON Result object.
[HttpGet]
public async Task<IActionResult> GetPeopleList(FilterPersonListViewModel model)
{
_logger.LogInformation(
message: GetLogDetail());
//check if model is empty and if so send a empty collection back to initialise the table
if (IsFilterModelValid(model))
{
ICollection<PersonEntityListViewModel> elvm = new List<PersonEntityListViewModel>();
return Json(elvm);
}
bool isCanstat = _userService.IsInRole(User, Constants.Role.Canstat);
var result = await _entityService.GetFilterPersonListViewModelAsync(model, isCanstat);
var data = result.Model;
return Json(data);
}
I then added the middleware to use Gzip compression in my Startup.cs file by adding the line ConfigureServices and Configure as it says to in https://learn.microsoft.com/en-us/aspnet/core/performance/response-compression?view=aspnetcore-2.1. The problem is it doesn't say how to send the response as Gzip. It says "Submit a request to the sample app with the Accept-Encoding: gzip header and observe that the response is compressed." but it doesn't say how I would enable that header in my response.
Do I have to do anything special to compress my data object when I send it back as Json? I found a few different articles relating to compressing it via GzipStream but then I can't send it back as an ActionResult it would seem?
"ajax": {
"url": "/Person/GetPeopleList",
"type": "GET",
//"contentType": "application/json",
"data": function (d) {
setFilterData();
Object.assign(d, filterData);
return d;
},
"dataSrc": ""
},