Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
Merge branch 'dev' into VP-5616
Browse files Browse the repository at this point in the history
  • Loading branch information
trueboroda committed Oct 23, 2020
2 parents 2768ea7 + e49ade5 commit 7dd65ae
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsageEvent> events)
{
//Nothing todo
return Task.FromResult(true);
}

Expand All @@ -49,22 +48,27 @@ public RecommendationEvalContext CreateEvalContext()
public async Task<Product[]> 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<Product>();
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();
});
}
Expand Down
1 change: 1 addition & 0 deletions VirtoCommerce.Storefront/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7dd65ae

Please sign in to comment.