Skip to content

Commit 888c875

Browse files
committed
chore: group listings performance
1 parent d071b9c commit 888c875

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

server/StrDss.Data/Repositories/RentalListingRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public async Task<PagedDto<RentalListingGroupDto>> GetGroupedRentalListings(stri
9494
ApplyFilters(all, address, url, listingId, hostName, businessLicence, prRequirement, blRequirement, lgId, statusArray, reassigned, takedownComplete, ref query);
9595

9696
var groupedQuery = query
97+
.AsNoTracking()
9798
.GroupBy(x => new { x.EffectiveBusinessLicenceNo, x.EffectiveHostNm, x.MatchAddressTxt })
9899
.Select(g => new RentalListingGroupDto
99100
{

server/StrDss.Data/Repositories/RepositoryBase.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
using StrDss.Common;
55
using StrDss.Data.Entities;
66
using StrDss.Model;
7+
using System.Diagnostics;
78

89
namespace StrDss.Data.Repositories
910
{
10-
public interface IRepositoryBase<TEntity>
11+
public interface IRepositoryBase<TEntity>
1112
where TEntity : class
1213
{
1314
Task<PagedDto<TOutput>> Page<TInput, TOutput>(IQueryable<TInput> list, int pageSize, int pageNumber, string orderBy, string direction, string extraSort = "");
@@ -35,8 +36,16 @@ public RepositoryBase(DssDbContext dbContext, IMapper mapper, ICurrentUser curre
3536

3637
public async Task<PagedDto<TOutput>> Page<TInput, TOutput>(IQueryable<TInput> list, int pageSize, int pageNumber, string orderBy, string direction = "", string extraSort = "")
3738
{
39+
var stopwatch = Stopwatch.StartNew();
40+
3841
var totalRecords = list.Count();
3942

43+
stopwatch.Stop();
44+
45+
_logger.LogDebug($"Get Grouped Listings (group) - Counting groups. Page Size: {pageSize}, Page Number: {pageNumber}, Time: {stopwatch.Elapsed.TotalSeconds} seconds");
46+
47+
stopwatch.Restart();
48+
4049
if (pageNumber <= 0) pageNumber = 1;
4150

4251
var sort = "";
@@ -49,7 +58,7 @@ public async Task<PagedDto<TOutput>> Page<TInput, TOutput>(IQueryable<TInput> li
4958
{
5059
sort = $"{orderBy} {direction}, {extraSort}";
5160
}
52-
else
61+
else
5362
{
5463
sort = $"{extraSort}";
5564
}
@@ -65,6 +74,12 @@ public async Task<PagedDto<TOutput>> Page<TInput, TOutput>(IQueryable<TInput> li
6574

6675
var result = await pagedList.ToListAsync();
6776

77+
stopwatch.Stop();
78+
79+
_logger.LogDebug($"Get Grouped Listings (group) - Getting groups. Time: {stopwatch.Elapsed.TotalSeconds} seconds");
80+
81+
stopwatch.Restart();
82+
6883
IEnumerable<TOutput> outputList;
6984

7085
if (typeof(TOutput) != typeof(TInput))
@@ -75,7 +90,8 @@ public async Task<PagedDto<TOutput>> Page<TInput, TOutput>(IQueryable<TInput> li
7590
var pagedDTO = new PagedDto<TOutput>
7691
{
7792
SourceList = outputList,
78-
PageInfo = new PageInfo {
93+
PageInfo = new PageInfo
94+
{
7995
PageNumber = pageNumber,
8096
PageSize = pageSize,
8197
TotalCount = totalRecords,
@@ -85,6 +101,10 @@ public async Task<PagedDto<TOutput>> Page<TInput, TOutput>(IQueryable<TInput> li
85101
}
86102
};
87103

104+
stopwatch.Stop();
105+
106+
_logger.LogDebug($"Get Grouped Listings (group) - Mapping groups to DTO. Time: {stopwatch.Elapsed.TotalSeconds} seconds");
107+
88108
return pagedDTO;
89109
}
90110
}

0 commit comments

Comments
 (0)