Skip to content

Commit

Permalink
Merge branch 'release/3.811.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
vc-ci committed Oct 10, 2024
2 parents ad839ce + fde095a commit d7a0ad7
Show file tree
Hide file tree
Showing 6 changed files with 464 additions and 191 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<!-- These properties will be shared for all projects -->
<PropertyGroup>
<VersionPrefix>3.810.0</VersionPrefix>
<VersionPrefix>3.811.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<VersionSuffix Condition=" '$(VersionSuffix)' != '' AND '$(BuildNumber)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,53 @@

namespace VirtoCommerce.NotificationsModule.Data.Services
{
public class NotificationMessageSearchService : INotificationMessageSearchService
public class NotificationMessageSearchService(
Func<INotificationRepository> repositoryFactory,
INotificationMessageService messageService)
: INotificationMessageSearchService
{
private readonly Func<INotificationRepository> _repositoryFactory;
private readonly INotificationMessageService _messageService;

public NotificationMessageSearchService(Func<INotificationRepository> repositoryFactory, INotificationMessageService messageService)
public async Task<NotificationMessageSearchResult> SearchMessageAsync(
NotificationMessageSearchCriteria criteria)
{
_repositoryFactory = repositoryFactory;
_messageService = messageService;
}
var result = AbstractTypeFactory<NotificationMessageSearchResult>.TryCreateInstance();

public async Task<NotificationMessageSearchResult> SearchMessageAsync(NotificationMessageSearchCriteria criteria)
{
var result = new NotificationMessageSearchResult();
using var repository = repositoryFactory();
repository.DisableChangesTracking();

using (var repository = _repositoryFactory())
{
//Optimize performance and CPU usage
repository.DisableChangesTracking();
result.Results = new List<NotificationMessage>();
var query = BuildQuery(repository, criteria);
var needExecuteCount = criteria.Take == 0;

result.Results = new List<NotificationMessage>();
var query = BuildQuery(repository, criteria);
var sortInfos = BuildSortExpression(criteria);
if (criteria.Take > 0)
{
var messageIds = await query
.OrderBySortInfos(BuildSortExpression(criteria)).ThenBy(x => x.Id)
.Select(x => x.Id)
.Skip(criteria.Skip).Take(criteria.Take)
.ToArrayAsync();

result.TotalCount = await query.CountAsync();
var unorderedResults = await messageService.GetNotificationsMessageByIds(messageIds);
result.Results = unorderedResults.OrderBy(x => Array.IndexOf(messageIds, x.Id)).ToList();
result.TotalCount = messageIds.Length;

if (criteria.Take > 0)
if (criteria.Skip > 0 || result.TotalCount == criteria.Take)
{
var messageIds = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id)
.Select(x => x.Id)
.Skip(criteria.Skip).Take(criteria.Take)
.ToArrayAsync();

var unorderedResults = await _messageService.GetNotificationsMessageByIds(messageIds);
result.Results = unorderedResults.OrderBy(x => Array.IndexOf(messageIds, x.Id)).ToList();
needExecuteCount = true;
}
}

if (needExecuteCount)
{
result.TotalCount = await query.CountAsync();
}


return result;
}

protected virtual IQueryable<NotificationMessageEntity> BuildQuery(INotificationRepository repository, NotificationMessageSearchCriteria criteria)
protected virtual IQueryable<NotificationMessageEntity> BuildQuery(
INotificationRepository repository,
NotificationMessageSearchCriteria criteria)
{
var query = repository.NotificationMessages;

Expand All @@ -81,8 +86,22 @@ protected virtual IQueryable<NotificationMessageEntity> BuildQuery(INotification
if (!string.IsNullOrEmpty(criteria.Keyword))
{
query = query.Where(x =>
(x is EmailNotificationMessageEntity && ((EmailNotificationMessageEntity)x).To.Contains(criteria.Keyword))
|| x.NotificationType.Contains(criteria.Keyword));
x.Status != null && x.Status.Contains(criteria.Keyword) ||
x.NotificationType != null && x.NotificationType.Contains(criteria.Keyword) ||
x.LastSendError != null && x.LastSendError.Contains(criteria.Keyword) ||
(x is EmailNotificationMessageEntity && (
(((EmailNotificationMessageEntity)x).To != null &&
((EmailNotificationMessageEntity)x).To.Contains(criteria.Keyword)) ||
(((EmailNotificationMessageEntity)x).From != null &&
((EmailNotificationMessageEntity)x).From.Contains(criteria.Keyword)) ||
(((EmailNotificationMessageEntity)x).Subject != null &&
((EmailNotificationMessageEntity)x).Subject.Contains(criteria.Keyword)) ||
(((EmailNotificationMessageEntity)x).CC != null &&
((EmailNotificationMessageEntity)x).CC.Contains(criteria.Keyword)) ||
(((EmailNotificationMessageEntity)x).BCC != null &&
((EmailNotificationMessageEntity)x).BCC.Contains(criteria.Keyword)) ||
(((EmailNotificationMessageEntity)x).Body != null &&
((EmailNotificationMessageEntity)x).Body.Contains(criteria.Keyword)))));
}

return query;
Expand All @@ -91,19 +110,20 @@ protected virtual IQueryable<NotificationMessageEntity> BuildQuery(INotification
protected virtual IList<SortInfo> BuildSortExpression(NotificationMessageSearchCriteria criteria)
{
var sortInfos = criteria.SortInfos;

if (sortInfos.IsNullOrEmpty())
{
sortInfos = new[]
{
sortInfos =
[
new SortInfo
{
SortColumn = nameof(NotificationMessageEntity.CreatedDate),
SortDirection = SortDirection.Descending
}
};
];
}

return sortInfos;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ angular.module('virtoCommerce.notificationsModule')
}

blade.refresh = function () {
blade.isLoading = true;

var searchCriteria = getSearchCriteria();
notifications.getNotificationJournalList(searchCriteria, function (data) {
blade.currentEntities = data.results;
Expand Down
2 changes: 1 addition & 1 deletion src/VirtoCommerce.NotificationsModule.Web/module.manifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<module xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<id>VirtoCommerce.Notifications</id>
<version>3.810.0</version>
<version>3.811.0</version>
<version-tag />
<platformVersion>3.853.0</platformVersion>
<dependencies>
Expand Down
Loading

0 comments on commit d7a0ad7

Please sign in to comment.