Skip to content

Commit

Permalink
Merge pull request #671 from bcgov/yj
Browse files Browse the repository at this point in the history
chore: page perf
  • Loading branch information
ychung-mot authored Sep 20, 2024
2 parents 0986661 + 6907749 commit da8d7d2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion server/StrDss.Data/Repositories/RepositoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public RepositoryBase(DssDbContext dbContext, IMapper mapper, ICurrentUser curre
public async Task<PagedDto<TOutput>> Page<TInput, TOutput>(IQueryable<TInput> list, int pageSize, int pageNumber, string orderBy, string direction = "", string extraSort = "", bool count = true)
{
var stopwatch = Stopwatch.StartNew();
int? totalRecords = null;

var totalRecords = await list.CountAsync();
if (count) totalRecords = await list.CountAsync();

if (pageNumber <= 0) pageNumber = 1;

Expand Down
2 changes: 1 addition & 1 deletion server/StrDss.Model/PageDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public int PageNumber

public int PageSize { get; set; }
public int ItemCount { get; set; }
public int TotalCount { get; set; }
public int? TotalCount { get; set; }
public int PageCount => PageSize == 0 ? 1 : ((int)(TotalCount / PageSize) + (TotalCount % PageSize == 0 ? 0 : 1));

Check warning on line 20 in server/StrDss.Model/PageDto.cs

View workflow job for this annotation

GitHub Actions / test-backend

Nullable value type may be null.
public bool HasPreviousPage => PageNumber != 1;
public bool HasNextPage => PageNumber < PageCount;
Expand Down

0 comments on commit da8d7d2

Please sign in to comment.