Witam.
Zauważyłem pewien problem i nie bardzo wiem dlaczego występuje. Pierwszy raz zrobiłem API, w którym paginacja jest po stronie SQLa. Wcześniej miałem raczej umiarkowaną ilość danych i mogłem sobie to ogarnąć za pomocą linq.
ZAPYTANIE - 52 strona to guzik Last page
w SPA (Angular). Ja wiem, że nikt nie klika stron dla oglądania danych ale na ostatnią ktoś może przejść.
select
*
from
Documents
where Type = 308
and DocumentDate between '2021-02-17' and '2021-02-17'
order by Id desc
offset 52 rows
fetch next 10 rows only;
select count(*)
from Documents
where Type = 308
and DocumentDate between '2021-02-17' and '2021-02-17'
DAPPER - gdzieś w jakimś artykule widziałem ten sposób wyciągania wielu zapytań na raz
var documents = new DocumentsResponse();
using (var db = _dbConnectionFactory.CreateCompanyConnection())
{
using (var multi = await db.QueryMultipleAsync(query, new { Page = filter.Limit * filter.Page, filter.Limit, filter.Type, filter.StartDate, filter.EndDate }))
{
documents.Data = multi.Read<Document>();
documents.DataLength = multi.ReadFirst<int>();
}
}
return documents;
CZAS
Strona 1 = 2.31s
Strona 2 = 2.22s
Strona 3 = 2.75s
Strona 4 = 3.42s
Ze strony 4 na ostatnią = 24.90s
Ze strony 1 na ostatnią = 23.64s
Z ostatniej na 1 = 1.94s
Wszystko na localhost, w debugu. API w .NET 5, SPA w Angular 11.