Пример #1
0
        private ItemsResult GetInstantMixResult(BaseGetSimilarItems request, IEnumerable <string> genres)
        {
            var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null;

            var fields = request.GetItemFields().ToList();

            var inputItems = user == null
                                 ? _libraryManager.RootFolder.RecursiveChildren
                                 : user.RootFolder.GetRecursiveChildren(user);

            var genresDictionary = genres.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);

            var limit = request.Limit.HasValue ? request.Limit.Value * 2 : 100;

            var items = inputItems
                        .OfType <Audio>()
                        .Select(i => new Tuple <Audio, int>(i, i.Genres.Count(genresDictionary.ContainsKey)))
                        .OrderByDescending(i => i.Item2)
                        .ThenBy(i => Guid.NewGuid())
                        .Select(i => i.Item1)
                        .Take(limit)
                        .OrderBy(i => Guid.NewGuid())
                        .ToList();

            var result = new ItemsResult
            {
                TotalRecordCount = items.Count
            };

            var dtos = items.Take(request.Limit ?? items.Count)
                       .Select(i => _dtoService.GetBaseItemDto(i, fields, user));

            result.Items = dtos.ToArray();

            return(result);
        }
Пример #2
0
        private object GetResult(IEnumerable<Audio> items, User user, BaseGetSimilarItems request)
        {
            var fields = request.GetItemFields().ToList();

            var list = items.ToList();

            var result = new ItemsResult
            {
                TotalRecordCount = list.Count
            };

            var dtos = list.Take(request.Limit ?? list.Count)
                .Select(i => _dtoService.GetBaseItemDto(i, fields, user));

            result.Items = dtos.ToArray();

            return ToOptimizedResult(result);
        }
Пример #3
0
        private ItemsResult GetInstantMixResult(BaseGetSimilarItems request, IEnumerable<string> genres)
        {
            var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null;

            var fields = request.GetItemFields().ToList();

            var inputItems = user == null
                                 ? _libraryManager.RootFolder.RecursiveChildren
                                 : user.RootFolder.GetRecursiveChildren(user);

            var genresDictionary = genres.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);

            var limit = request.Limit.HasValue ? request.Limit.Value * 2 : 100;

            var items = inputItems
                .OfType<Audio>()
                .Select(i => new Tuple<Audio, int>(i, i.Genres.Count(genresDictionary.ContainsKey)))
                .OrderByDescending(i => i.Item2)
                .ThenBy(i => Guid.NewGuid())
                .Select(i => i.Item1)
                .Take(limit)
                .OrderBy(i => Guid.NewGuid())
                .ToList();

            var result = new ItemsResult
            {
                TotalRecordCount = items.Count
            };

            var dtos = items.Take(request.Limit ?? items.Count)
                .Select(i => _dtoService.GetBaseItemDto(i, fields, user));

            result.Items = dtos.ToArray();

            return result;
        }
Пример #4
0
        private async Task<ItemsResult> GetInstantMixResult(BaseGetSimilarItems request, IEnumerable<string> genres)
        {
            var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null;

            var fields = request.GetItemFields().ToList();

            var dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository, _itemRepo);

            var inputItems = user == null
                                 ? _libraryManager.RootFolder.RecursiveChildren
                                 : user.RootFolder.GetRecursiveChildren(user);

            var genresDictionary = genres.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);

            var limit = request.Limit.HasValue ? request.Limit.Value * 2 : 100;

            var items = inputItems
                .OfType<Audio>()
                .Select(i => new Tuple<Audio, int>(i, i.Genres.Count(genresDictionary.ContainsKey)))
                .OrderByDescending(i => i.Item2)
                .ThenBy(i => Guid.NewGuid())
                .Select(i => i.Item1)
                .Take(limit)
                .OrderBy(i => Guid.NewGuid())
                .ToArray();

            var result = new ItemsResult
            {
                TotalRecordCount = items.Length
            };

            var tasks = items.Take(request.Limit ?? items.Length)
                .Select(i => dtoBuilder.GetBaseItemDto(i, fields, user));

            result.Items = await Task.WhenAll(tasks).ConfigureAwait(false);

            return result;
        }