Skip to content

Commit

Permalink
Convert various sync calls to async
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Aug 8, 2024
1 parent 324486b commit 733f1f8
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public virtual async Task<Customer> GetUserByExternalAuthenticationParametersAsy
{
ArgumentNullException.ThrowIfNull(parameters);

var associationRecord = _externalAuthenticationRecordRepository.Table.FirstOrDefault(record =>
var associationRecord = await _externalAuthenticationRecordRepository.Table.FirstOrDefaultAsync(record =>
record.ExternalIdentifier.Equals(parameters.ExternalIdentifier) && record.ProviderSystemName.Equals(parameters.ProviderSystemName));
if (associationRecord == null)
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/Nop.Services/Catalog/CategoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public virtual async Task ClearDiscountCategoryMappingAsync(Discount discount)

var mappings = _discountCategoryMappingRepository.Table.Where(dcm => dcm.DiscountId == discount.Id);

await _discountCategoryMappingRepository.DeleteAsync(mappings.ToList());
await _discountCategoryMappingRepository.DeleteAsync(await mappings.ToListAsync());
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Libraries/Nop.Services/Catalog/ManufacturerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public virtual async Task ClearDiscountManufacturerMappingAsync(Discount discoun

var mappings = _discountManufacturerMappingRepository.Table.Where(dcm => dcm.DiscountId == discount.Id);

await _discountManufacturerMappingRepository.DeleteAsync(mappings.ToList());
await _discountManufacturerMappingRepository.DeleteAsync(await mappings.ToListAsync());
}

/// <summary>
Expand Down Expand Up @@ -488,7 +488,7 @@ public virtual async Task<string[]> GetNotExistingManufacturersAsync(string[] ma
var query = _manufacturerRepository.Table;//.Where(m => !m.Deleted);
var queryFilter = manufacturerIdsNames.Distinct().ToArray();
//filtering by name
var filter = query.Select(m => m.Name).Where(m => queryFilter.Contains(m)).ToList();
var filter = await query.Select(m => m.Name).Where(m => queryFilter.Contains(m)).ToListAsync();
queryFilter = queryFilter.Except(filter).ToArray();

//if some names not found
Expand Down
17 changes: 9 additions & 8 deletions src/Libraries/Nop.Services/Catalog/ProductService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Data.SqlTypes;
using LinqToDB;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Domain.Catalog;
Expand Down Expand Up @@ -662,7 +663,7 @@ where p.Published && !p.Deleted && p.VisibleIndividually &&
//apply ACL constraints
query = await _aclService.ApplyAcl(query, customerRoleIds);
featuredProducts = query.ToList();
featuredProducts = await query.ToListAsync();
return featuredProducts.Select(p => p.Id).ToList();
});
Expand Down Expand Up @@ -709,7 +710,7 @@ where p.Published && !p.Deleted && p.VisibleIndividually &&
//apply ACL constraints
query = await _aclService.ApplyAcl(query, customerRoleIds);
return query.Select(p => p.Id).ToList();
return await query.Select(p => p.Id).ToListAsync();
});

if (!featuredProducts.Any() && featuredProductIds.Any())
Expand Down Expand Up @@ -786,7 +787,7 @@ where categoryIds.Contains(pc.CategoryId)
.PrepareKeyForDefaultCache(NopCatalogDefaults.CategoryProductsNumberCacheKey, customerRoleIds, storeId, categoryIds);

//only distinct products
return await _staticCacheManager.GetAsync(cacheKey, () => query.Select(p => p.Id).Count());
return await _staticCacheManager.GetAsync(cacheKey, () => query.Select(p => p.Id).CountAsync(default(CancellationToken)));
}

/// <summary>
Expand Down Expand Up @@ -1243,7 +1244,7 @@ public virtual async Task UpdateProductReviewTotalsAsync(Product product)

var reviews = _productReviewRepository.Table
.Where(r => r.ProductId == product.Id)
.ToAsyncEnumerable();
.AsAsyncEnumerable();
await foreach (var pr in reviews)
if (pr.IsApproved)
{
Expand Down Expand Up @@ -1363,7 +1364,7 @@ orderby p.Id
where !p.Deleted &&
p.Sku == sku
select p;
var product = await query.FirstOrDefaultAsync();
var product = await query.FirstOrDefaultAsync(default(CancellationToken));

return product;
}
Expand Down Expand Up @@ -2545,8 +2546,8 @@ public virtual async Task SetProductReviewHelpfulnessAsync(ProductReview product
ArgumentNullException.ThrowIfNull(productReview);

var customer = await _workContext.GetCurrentCustomerAsync();
var prh = _productReviewHelpfulnessRepository.Table
.SingleOrDefault(h => h.ProductReviewId == productReview.Id && h.CustomerId == customer.Id);
var prh = await _productReviewHelpfulnessRepository.Table
.SingleOrDefaultAsync(h => h.ProductReviewId == productReview.Id && h.CustomerId == customer.Id);

if (prh is null)
{
Expand Down Expand Up @@ -2755,7 +2756,7 @@ join p in _productRepository.Table on dcm.EntityId equals p.Id
select new { product = p, dcm };

var mappingsToDelete = new List<DiscountProductMapping>();
await foreach (var pdcm in mappingsWithProducts.ToAsyncEnumerable())
await foreach (var pdcm in mappingsWithProducts.AsAsyncEnumerable())
{
mappingsToDelete.Add(pdcm.dcm);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/Nop.Services/Catalog/ProductTagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ group ptm by ptm.ProductTagId into ptmGrouped
ProductCount = ptmGrouped.Count()
};
return pTagCount.ToDictionary(item => item.ProductTagId, item => item.ProductCount);
return await pTagCount.ToDictionaryAsync(item => item.ProductTagId, item => item.ProductCount);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/Nop.Services/Discounts/DiscountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public virtual async Task<IList<Discount>> GetAllDiscountsAsync(DiscountType? di
discounts = discounts.Where(discount =>
!discount.EndDateUtc.HasValue || discount.EndDateUtc <= endDateUtc.Value);

return discounts.ToList();
return await discounts.ToListAsync();
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/Libraries/Nop.Services/Forums/ForumService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,14 @@ public virtual async Task DeleteForumAsync(Forum forum)
where queryTopicIds.Contains(fs.TopicId)
select fs;

await _forumSubscriptionRepository.DeleteAsync(queryFs1.ToList());
await _forumSubscriptionRepository.DeleteAsync(await queryFs1.ToListAsync());

//delete forum subscriptions (forum)
var queryFs2 = from fs in _forumSubscriptionRepository.Table
where fs.ForumId == forum.Id
select fs;

await _forumSubscriptionRepository.DeleteAsync(queryFs2.ToList());
await _forumSubscriptionRepository.DeleteAsync(await queryFs2.ToListAsync());

//delete forum
await _forumRepository.DeleteAsync(forum);
Expand Down Expand Up @@ -415,7 +415,7 @@ public virtual async Task DeleteTopicAsync(ForumTopic forumTopic)
var queryFs = from ft in _forumSubscriptionRepository.Table
where ft.TopicId == forumTopic.Id
select ft;
var forumSubscriptions = queryFs.ToList();
var forumSubscriptions = await queryFs.ToListAsync();

await _forumSubscriptionRepository.DeleteAsync(forumSubscriptions);

Expand Down
Loading

0 comments on commit 733f1f8

Please sign in to comment.