Skip to content

Commit 81ff8e2

Browse files
Execute repository queries on the driver instead of blocking a thread (#776)
1 parent 4f0e3f7 commit 81ff8e2

79 files changed

Lines changed: 356 additions & 229 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/Business/Grand.Business.Authentication/Services/ExternalAuthenticationService.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Grand.Business.Core.Commands.Customers;
1+
using Grand.Business.Core.Commands.Customers;
22
using Grand.Business.Core.Events.Customers;
33
using Grand.Business.Core.Extensions;
44
using Grand.Business.Core.Interfaces.Authentication;
@@ -327,7 +327,7 @@ public virtual async Task<IList<ExternalAuthentication>> GetExternalIdentifiers(
327327
var query = from p in _externalAuthenticationRecordRepository.Table
328328
where p.CustomerId == customer.Id
329329
select p;
330-
return await Task.FromResult(query.ToList());
330+
return await _externalAuthenticationRecordRepository.ToListAsync(query);
331331
}
332332

333333
/// <summary>

‎src/Business/Grand.Business.Catalog/Services/Brands/BrandLayoutService.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Grand.Business.Core.Interfaces.Catalog.Brands;
1+
using Grand.Business.Core.Interfaces.Catalog.Brands;
22
using Grand.Data;
33
using Grand.Domain.Catalog;
44
using Grand.Infrastructure.Caching;
@@ -53,7 +53,7 @@ public virtual async Task<IList<BrandLayout>> GetAllBrandLayouts()
5353
var query = from pt in _brandLayoutRepository.Table
5454
orderby pt.DisplayOrder
5555
select pt;
56-
return await Task.FromResult(query.ToList());
56+
return await _brandLayoutRepository.ToListAsync(query);
5757
});
5858
}
5959

‎src/Business/Grand.Business.Catalog/Services/Brands/BrandService.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Grand.Business.Core.Interfaces.Catalog.Brands;
1+
using Grand.Business.Core.Interfaces.Catalog.Brands;
22
using Grand.Data;
33
using Grand.Domain;
44
using Grand.Domain.Catalog;
@@ -166,7 +166,7 @@ public virtual async Task<IList<Brand>> GetAllBrandsByDiscount(string discountId
166166
where c.AppliedDiscounts.Any(x => x == discountId)
167167
select c;
168168

169-
return await Task.FromResult(query.ToList());
169+
return await _brandRepository.ToListAsync(query);
170170
}
171171

172172
#endregion

‎src/Business/Grand.Business.Catalog/Services/Categories/CategoryLayoutService.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Grand.Business.Core.Interfaces.Catalog.Categories;
1+
using Grand.Business.Core.Interfaces.Catalog.Categories;
22
using Grand.Data;
33
using Grand.Domain.Catalog;
44
using Grand.Infrastructure.Caching;
@@ -53,7 +53,7 @@ public virtual async Task<IList<CategoryLayout>> GetAllCategoryLayouts()
5353
var query = from pt in _categoryLayoutRepository.Table
5454
orderby pt.DisplayOrder
5555
select pt;
56-
return await Task.FromResult(query.ToList());
56+
return await _categoryLayoutRepository.ToListAsync(query);
5757
});
5858
}
5959

‎src/Business/Grand.Business.Catalog/Services/Categories/CategoryService.cs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public virtual async Task<IList<Category>> GetMenuCategories()
129129
{
130130
case true when
131131
string.IsNullOrEmpty(CurrentStore.Id) || _accessControlConfig.IgnoreStoreLimitations:
132-
return await Task.FromResult(query.ToList());
132+
return await _categoryRepository.ToListAsync(query);
133133
case false:
134134
{
135135
//Limited to customer group (access control list)
@@ -146,7 +146,7 @@ public virtual async Task<IList<Category>> GetMenuCategories()
146146
query = from p in query
147147
where !p.LimitedToStores || p.Stores.Contains(CurrentStore.Id)
148148
select p;
149-
return await Task.FromResult(query.ToList());
149+
return await _categoryRepository.ToListAsync(query);
150150
}
151151

152152
/// <summary>
@@ -217,7 +217,7 @@ public virtual async Task<IList<Category>> GetAllCategoriesDisplayedOnHomePage(b
217217
var query = _categoryRepository.Table
218218
.Where(x => x.Published && x.ShowOnHomePage)
219219
.OrderBy(x => x.DisplayOrder);
220-
var categories = await Task.FromResult(query.ToList());
220+
var categories = await _categoryRepository.ToListAsync(query);
221221
if (!showHidden)
222222
categories = categories
223223
.Where(c => _aclService.Authorize(c, CurrentCustomer) &&
@@ -238,7 +238,7 @@ public virtual async Task<IList<Category>> GetAllCategoriesFeaturedProductsOnHom
238238
.Where(x => x.Published && x.FeaturedProductsOnHomePage)
239239
.OrderBy(x => x.DisplayOrder);
240240

241-
var categories = await Task.FromResult(query.ToList());
241+
var categories = await _categoryRepository.ToListAsync(query);
242242
if (!showHidden)
243243
categories = categories
244244
.Where(c => _aclService.Authorize(c, CurrentCustomer) &&
@@ -257,7 +257,7 @@ public virtual async Task<IList<Category>> GetAllCategoriesSearchBox()
257257
.Where(x => x.Published && x.ShowOnSearchBox)
258258
.OrderBy(x => x.SearchBoxDisplayOrder);
259259

260-
var categories = (await Task.FromResult(query.ToList()))
260+
var categories = (await _categoryRepository.ToListAsync(query))
261261
.Where(c => _aclService.Authorize(c, CurrentCustomer) &&
262262
_aclService.Authorize(c, CurrentStore.Id))
263263
.ToList();
@@ -392,7 +392,7 @@ public virtual async Task<IList<Category>> GetAllCategoriesByDiscount(string dis
392392
where c.AppliedDiscounts.Any(x => x == discountId)
393393
select c;
394394

395-
return await Task.FromResult(query.ToList());
395+
return await _categoryRepository.ToListAsync(query);
396396
}
397397

398398
/// <summary>

‎src/Business/Grand.Business.Catalog/Services/Collections/CollectionLayoutService.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Grand.Business.Core.Interfaces.Catalog.Collections;
1+
using Grand.Business.Core.Interfaces.Catalog.Collections;
22
using Grand.Data;
33
using Grand.Domain.Catalog;
44
using Grand.Infrastructure.Caching;
@@ -53,7 +53,7 @@ public virtual async Task<IList<CollectionLayout>> GetAllCollectionLayouts()
5353
var query = from pt in _collectionLayoutRepository.Table
5454
orderby pt.DisplayOrder
5555
select pt;
56-
return await Task.FromResult(query.ToList());
56+
return await _collectionLayoutRepository.ToListAsync(query);
5757
});
5858
}
5959

‎src/Business/Grand.Business.Catalog/Services/Collections/CollectionService.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Grand.Business.Core.Interfaces.Catalog.Collections;
1+
using Grand.Business.Core.Interfaces.Catalog.Collections;
22
using Grand.Business.Core.Interfaces.Common.Security;
33
using Grand.Data;
44
using Grand.Domain;
@@ -109,7 +109,7 @@ public virtual async Task<IList<Collection>> GetAllCollectionFeaturedProductsOnH
109109
var query = _collectionRepository.Table.Where(x => x.Published && x.FeaturedProductsOnHomePage)
110110
.OrderBy(x => x.DisplayOrder);
111111

112-
var collections = await Task.FromResult(query.ToList());
112+
var collections = await _collectionRepository.ToListAsync(query);
113113
if (!showHidden)
114114
collections = collections
115115
.Where(c => _aclService.Authorize(c, _contextAccessor.WorkContext.CurrentCustomer) &&
@@ -193,7 +193,7 @@ public virtual async Task<IList<Collection>> GetAllCollectionsByDiscount(string
193193
where c.AppliedDiscounts.Any(x => x == discountId)
194194
select c;
195195

196-
return await Task.FromResult(query.ToList());
196+
return await _collectionRepository.ToListAsync(query);
197197
}
198198

199199
#endregion

‎src/Business/Grand.Business.Catalog/Services/Directory/MeasureService.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Grand.Business.Core.Interfaces.Catalog.Directory;
1+
using Grand.Business.Core.Interfaces.Catalog.Directory;
22
using Grand.Data;
33
using Grand.Domain.Directory;
44
using Grand.Infrastructure.Caching;
@@ -94,7 +94,7 @@ public virtual async Task<IList<MeasureDimension>> GetAllMeasureDimensions()
9494
var query = from md in _measureDimensionRepository.Table
9595
orderby md.DisplayOrder
9696
select md;
97-
return await Task.FromResult(query.ToList());
97+
return await _measureDimensionRepository.ToListAsync(query);
9898
});
9999
}
100100

@@ -250,7 +250,7 @@ public virtual async Task<IList<MeasureWeight>> GetAllMeasureWeights()
250250
var query = from mw in _measureWeightRepository.Table
251251
orderby mw.DisplayOrder
252252
select mw;
253-
return await Task.FromResult(query.ToList());
253+
return await _measureWeightRepository.ToListAsync(query);
254254
});
255255
}
256256

@@ -391,7 +391,7 @@ public virtual async Task<IList<MeasureUnit>> GetAllMeasureUnits()
391391
var query = from md in _measureUnitRepository.Table
392392
orderby md.DisplayOrder
393393
select md;
394-
return await Task.FromResult(query.ToList());
394+
return await _measureUnitRepository.ToListAsync(query);
395395
});
396396
}
397397

‎src/Business/Grand.Business.Catalog/Services/Directory/SearchTermService.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Grand.Business.Core.Interfaces.Catalog.Directory;
1+
using Grand.Business.Core.Interfaces.Catalog.Directory;
22
using Grand.Business.Core.Utilities.Catalog;
33
using Grand.Data;
44
using Grand.Domain;
@@ -71,7 +71,7 @@ public virtual async Task<SearchTerm> GetSearchTermByKeyword(string keyword, str
7171
var query = from st in _searchTermRepository.Table
7272
where st.Keyword == keyword && st.StoreId == storeId
7373
select st;
74-
return await Task.FromResult(query.FirstOrDefault());
74+
return await _searchTermRepository.FirstOrDefaultAsync(query);
7575
}
7676

7777
/// <summary>

‎src/Business/Grand.Business.Catalog/Services/Discounts/DiscountService.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public virtual async Task<IList<Discount>> GetDiscountsQuery(DiscountType? disco
115115

116116
query = query.OrderBy(d => d.Name);
117117

118-
return await Task.FromResult(query.ToList());
118+
return await _discountRepository.ToListAsync(query);
119119
}
120120

121121
/// <summary>

0 commit comments

Comments
 (0)