I have a table that will contain 300,000 records and I need to create a smart paging and performance. I found many tutorials on the net that teach paging using PagedList, but in all cases, all the records are loaded and then pagination is done. In my case, I need to page before:
My app is in DDD standard and I have a repository. My current paging is working, but if I play 300,000 records in the bank, turn up a cart.
Below, my controller, View and Repository
[HttpGet]
[AllowAnonymous]
[Route("situacoes-gerenciamento/listar-todos")]
public IActionResult Index(string busca = "", int pagina = 1, int tamanhoPagina = 10)
{
var pessoasSituacoes =_pessoaSituacaoAppService.GetAll().ToPagedList(pagina, tamanhoPagina);
ViewBag.Busca = busca;
ViewBag.TamanhoPagina = tamanhoPagina;
return View(pessoasSituacoes);
}
@using X.PagedList.Mvc.Core;
@model X.PagedList.PagedList<SistemaComercial.Application.ViewModels.PessoaSituacao.PessoaSituacaoViewModel>
@{
ViewData["Title"] = "Gerenciar Situações de Pessoa";
}
<div class="panel animsition">
<div class="page-header">
<h1 class="page-title">@ViewData["Title"]</h1>
<ol class="breadcrumb">
<li><a asp-action="Index" asp-controller="Home">Home</a></li>
<li class="active">situacoes-gerenciamento/listar-todos</li>
</ol>
<div class="page-header-actions">
<div class="btn-group btn-group-sm"
role="group">
<a id="btnNovo" asp-action="Create" data-modal="" class="btn btn-outline btn-default new" data-toggle="tooltip"
data-original-title="Cadastrar Novo" data-container="body">
<span title="Cadastrar Novo" class="icon wb-plus"></span> Cadastrar Novo
</a>
<button type="button" class="btn btn-outline btn-default" data-toggle="tooltip"
data-original-title="Configurações" data-container="body">
<i class="icon wb-settings" aria-hidden="true"></i>
</button>
<button type="button" class="btn btn-outline btn-default" data-toggle="tooltip"
data-original-title="Exportar" data-container="body">
<i class="icon wb-upload" aria-hidden="true"></i>
</button>
<button type="button" class="btn btn-outline btn-default" data-toggle="tooltip"
data-original-title="Importar" data-container="body">
<i class="icon wb-download" aria-hidden="true"></i>
</button>
<button type="button" class="btn btn-outline btn-default" data-toggle="tooltip"
data-original-title="Imprimir" data-container="body">
<i class="icon wb-print" aria-hidden="true"></i>
</button>
<button type="button" class="btn btn-outline btn-default" data-toggle="tooltip"
data-original-title="Pesquisa Avançada" data-container="body">
<i class="icon wb-search" aria-hidden="true"></i>
<span class="hidden-xs">Pesquisa Avançada</span>
</button>
</div>
</div>
</div>
<div class="page-content">
<table class="table table-bordered table-striped" id="dt">
<thead>
<tr>
<th>
Id
</th>
<th>
Descrição
</th>
<th>
Tipo de Pessoa)
</th>
<th>
@Html.DisplayName("Ações")
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Descricao)
</td>
<td>
@Html.DisplayFor(modelItem => item.PessoaTipoDescricao)
</td>
<td>
<a title="Editar" asp-action="Edit" asp-route-id="@item.Id" data-modal="" class="btn btn-sm btn-icon btn-pure btn-default on-default edit-row">
<span class="icon-2x wb-edit"></span>
</a>
<a title="Detalhes" asp-action="Details" asp-route-id="@item.Id" data-modal="" class="btn btn-sm btn-icon btn-pure btn-default on-default footable-row-detail-row">
<span class="icon-2x wb-search"></span>
</a>
<a title="Excluir" asp-action="Delete" asp-route-id="@item.Id" data-modal="" class="btn btn-sm btn-icon btn-pure btn-default on-default remove-row">
<span class="icon-2x wb-trash"></span>
</a>
<a title="Histórico" class="btn btn-sm btn-icon btn-pure btn-default on-default clockpicker" data-id="@item.Id" data-toggle="modal" data-target="#pessoaHistory" data-original-title="Histórico">
<span class="icon-2x wb-time"></span>
</a>
</td>
</tr>
}
</tbody>
</table>
<div class="row">
<div class="col-md-6">
@Html.PagedListPager(Model, pagina => Url.Action("Index", new { pagina, busca = ViewBag.Busca, tamanhoPagina = ViewBag.TamanhoPagina }))
</div>
<div class="col-md-6">
<span class="pull-right">
Listando registros de @Model.FirstItemOnPage a @Model.LastItemOnPage de um total de @Model.TotalItemCount
</span>
</div>
</div>
</div>
</div>
<div class="modal fade modal-primary" id="modalPessoaSituacao" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog" style="width: 45%; height: 500px;">
<div class="modal-content">
<div id="contentModal"></div>
</div>
</div>
</div>
@section scripts {
<script src="~/js/cadastros/pessoaSituacao/pessoaSituacao.js"></script>
}
public virtual IQueryable<TEntity> GetAll()
{
return DbSet;
}