From 38acc3a40508d5d35c08591a06e462f5cabefc80 Mon Sep 17 00:00:00 2001 From: Dmitry Pushnitsa Date: Wed, 21 Oct 2020 14:44:48 +0200 Subject: [PATCH 1/2] Add polling change expiration token to association service --- .../DynamicAssociationsProvider.cs | 32 +++++++++++-------- VirtoCommerce.Storefront/Startup.cs | 1 + 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/VirtoCommerce.Storefront/Domain/Recommendations/DynamicAssociationsProvider.cs b/VirtoCommerce.Storefront/Domain/Recommendations/DynamicAssociationsProvider.cs index 1e1b6944..b3994bb8 100644 --- a/VirtoCommerce.Storefront/Domain/Recommendations/DynamicAssociationsProvider.cs +++ b/VirtoCommerce.Storefront/Domain/Recommendations/DynamicAssociationsProvider.cs @@ -4,40 +4,39 @@ using System.Threading.Tasks; using Microsoft.Extensions.Caching.Memory; using VirtoCommerce.Storefront.AutoRestClients.DynamicAssociationsModuleModuleApi; -using VirtoCommerce.Storefront.Common; -using VirtoCommerce.Storefront.Model; +using VirtoCommerce.Storefront.Infrastructure; using VirtoCommerce.Storefront.Model.Caching; using VirtoCommerce.Storefront.Model.Catalog; using VirtoCommerce.Storefront.Model.Common.Caching; using VirtoCommerce.Storefront.Model.Recommendations; using VirtoCommerce.Storefront.Model.Services; -namespace VirtoCommerce.Storefront.Domain +namespace VirtoCommerce.Storefront.Domain.Recommendations { public class DynamicAssociationsProvider : IRecommendationsProvider { private readonly ICatalogService _catalogService; private readonly IAssociations _associationsApi; private readonly IStorefrontMemoryCache _memoryCache; + private readonly IApiChangesWatcher _apiChangesWatcher; - public DynamicAssociationsProvider(ICatalogService catalogService, IAssociations associationsApi, - IStorefrontMemoryCache memoryCache) + public DynamicAssociationsProvider( + ICatalogService catalogService, + IAssociations associationsApi, + IStorefrontMemoryCache memoryCache, + IApiChangesWatcher apiChangesWatcher + ) { _catalogService = catalogService; _associationsApi = associationsApi; _memoryCache = memoryCache; + _apiChangesWatcher = apiChangesWatcher; } - public string ProviderName - { - get - { - return "DynamicAssociations"; - } - } + + public string ProviderName => "DynamicAssociations"; public Task AddEventAsync(IEnumerable events) { - //Nothing todo return Task.FromResult(true); } @@ -49,22 +48,27 @@ public RecommendationEvalContext CreateEvalContext() public async Task GetRecommendationsAsync(RecommendationEvalContext context) { var dynamicAssociationsContext = context as DynamicAssociationsEvalContext; + if (dynamicAssociationsContext == null) { throw new InvalidCastException(nameof(context)); } - var cacheKey = CacheKey.With(GetType(), "GetRecommendationsAsync", context.GetCacheKey()); + var cacheKey = CacheKey.With(GetType(), nameof(GetRecommendationsAsync), context.GetCacheKey()); + return await _memoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(RecommendationsCacheRegion.CreateChangeToken()); + cacheEntry.AddExpirationToken(_apiChangesWatcher.CreateChangeToken()); var result = new List(); var recommendedProductIds = await _associationsApi.EvaluateDynamicAssociationsAsync(dynamicAssociationsContext.ToContextDto()); + if (recommendedProductIds != null) { result.AddRange(await _catalogService.GetProductsAsync(recommendedProductIds.ToArray(), ItemResponseGroup.Seo | ItemResponseGroup.Outlines | ItemResponseGroup.ItemWithPrices | ItemResponseGroup.ItemWithDiscounts | ItemResponseGroup.Inventory)); } + return result.ToArray(); }); } diff --git a/VirtoCommerce.Storefront/Startup.cs b/VirtoCommerce.Storefront/Startup.cs index e0f1d23b..0a13f54b 100644 --- a/VirtoCommerce.Storefront/Startup.cs +++ b/VirtoCommerce.Storefront/Startup.cs @@ -31,6 +31,7 @@ using VirtoCommerce.Storefront.Domain; using VirtoCommerce.Storefront.Domain.Cart.Demo; using VirtoCommerce.Storefront.Domain.Catalog; +using VirtoCommerce.Storefront.Domain.Recommendations; using VirtoCommerce.Storefront.Domain.Security; using VirtoCommerce.Storefront.Extensions; using VirtoCommerce.Storefront.Filters; From e49ade5b8954d5f2e2bb9219df106fb07f7ddb7c Mon Sep 17 00:00:00 2001 From: Alexandr Morogov <42555001+krankenbro@users.noreply.github.com> Date: Thu, 22 Oct 2020 17:11:10 +0200 Subject: [PATCH 2/2] VP-5059: Update Workflow (#34) --- .github/workflows/main.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b770425c..d912331d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -64,6 +64,11 @@ jobs: - name: SonarCloud End uses: VirtoCommerce/vc-github-actions/sonar-scanner-end@master + - name: Quality Gate + uses: VirtoCommerce/vc-github-actions/sonar-quality-gate@VP-5059 + with: + login: ${{secrets.SONAR_TOKEN}} + - name: Packaging run: vc-build Compress -skip Clean+Restore+Compile+Test @@ -77,11 +82,18 @@ jobs: tag: ${{ steps.image.outputs.taggedVersion }} dockerFiles: "https://raw.githubusercontent.com/VirtoCommerce/vc-docker/master/linux/storefront/Dockerfile" - # Step runs only on commit to master or dev brunch + - name: Publish to Blob + if: ${{ github.ref == 'refs/heads/dev' }} + id: blobRelease + uses: VirtoCommerce/vc-github-actions/publish-blob-release@VP-5059 + with: + blobSAS: ${{ secrets.BLOB_TOKEN }} + - name: Publish Github Release + if: ${{ github.ref == 'refs/heads/master' }} with: changelog: ${{ steps.changelog.outputs.changelog }} - uses: VirtoCommerce/vc-github-actions/publish-github-release@master + uses: VirtoCommerce/vc-github-actions/publish-github-release@VP-5059 # Step runs only on commit to master or dev brunch - name: Docker Login