Skip to content

Commit

Permalink
Merge pull request #22 from VirtoCommerce/feat/VCPS-import-improvements
Browse files Browse the repository at this point in the history
Add ProfileIds to SearchImportRunHistoryCriteria
  • Loading branch information
vladimir-buravlev authored Feb 28, 2024
2 parents ab0e644 + 2259d8d commit fa03206
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
using System.Collections.Generic;
using VirtoCommerce.Platform.Core.Common;

namespace VirtoCommerce.ImportModule.Core.Models.Search
{
public class SearchImportRunHistoryCriteria : SearchCriteriaBase
{
public string UserId { get; set; }

public string UserName { get; set; }

public string ProfileId { get; set; }

private IList<string> _profileIds;

public virtual IList<string> ProfileIds
{
get
{
if (_profileIds == null && !string.IsNullOrEmpty(ProfileId))
{
_profileIds = new[] { ProfileId };
}
return _profileIds;
}
set
{
_profileIds = value;
}
}

public string JobId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,21 @@ public async Task ImportAsync(ImportProfile importProfile, Func<ImportProgressIn
Description = "Import has been started",
};

var fixedSizeErrorsQueue = new FixedSizeQueue<ErrorInfo>(50);
var fixedSizeErrorsQueue = new FixedSizeQueue<ErrorInfo>(Math.Max(maxErrorsCountThreshold, 50));
// Import errors
var errorsCount = 0;
void ErrorCallback(ErrorInfo info)
{
errorsCount++;
fixedSizeErrorsQueue.Add(info);
_logger.LogError(info.ToString());
importProgress.Errors = fixedSizeErrorsQueue.GetTopValues().Select(x => x.ToString()).ToList();
if (errorsCount == maxErrorsCountThreshold)
{
importProgress.Errors.Add("The import process has been canceled because it exceeds the configured maximum errors limit");
_logger.LogError("The import process has been canceled because it exceeds the configured maximum errors limit");
const string limitErrorMessage = "The import process has been canceled because it exceeds the configured maximum errors limit";
importProgress.Errors.Add(limitErrorMessage);
_logger.LogError(limitErrorMessage);
}
importProgress.Errors = fixedSizeErrorsQueue.GetTopValues().Select(x => x.ToString()).ToArray();
progressCallback(importProgress).GetAwaiter().GetResult();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ protected override IQueryable<ImportRunHistoryEntity> BuildQuery(IRepository rep
query = query.Where(x => x.UserId == criteria.UserId);
}

if (!string.IsNullOrEmpty(criteria.ProfileId))
if (!criteria.ProfileIds.IsNullOrEmpty())
{
query = query.Where(x => x.ProfileId == criteria.ProfileId);
query = criteria.ProfileIds.Count == 1
? query.Where(x => x.ProfileId == criteria.ProfileIds[0])
: query.Where(x => criteria.ProfileIds.Contains(x.ProfileId));
}

if (!string.IsNullOrEmpty(criteria.JobId))
Expand Down

0 comments on commit fa03206

Please sign in to comment.