Esempio n. 1
0
        private void ClearCache(Notification[] notifications)
        {
            NotificationSearchCacheRegion.ExpireRegion();

            foreach (var item in notifications)
            {
                NotificationCacheRegion.ExpireEntity(item);
            }
        }
Esempio n. 2
0
        public async Task <NotificationSearchResult> SearchNotificationsAsync(NotificationSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), nameof(SearchNotificationsAsync), criteria.GetCacheKey());
            var notificationSearchResult = await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(NotificationSearchCacheRegion.CreateChangeToken());

                var result = AbstractTypeFactory <NotificationSearchResult> .TryCreateInstance();

                var sortInfos = BuildSortExpression(criteria);

                using (var repository = _repositoryFactory())
                {
                    //Optimize performance and CPU usage
                    repository.DisableChangesTracking();

                    var query         = BuildQuery(repository, criteria, sortInfos);
                    result.TotalCount = await query.CountAsync();

                    if (criteria.Take > 0)
                    {
                        var notificationIds = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id)
                                              .Select(x => x.Id)
                                              .Skip(criteria.Skip).Take(criteria.Take)
                                              .ToArrayAsync();
                        var unorderedResults = await _notificationService.GetByIdsAsync(notificationIds, criteria.ResponseGroup);
                        result.Results       = unorderedResults.OrderBy(x => Array.IndexOf(notificationIds, x.Id)).ToArray();

                        foreach (var notification in result.Results)
                        {
                            notification.ReduceDetails(criteria.ResponseGroup);
                        }
                    }
                }

                return(result);
            });

            return(notificationSearchResult.Clone() as NotificationSearchResult);
        }