示例#1
0
 public FeedUpdater(DbContextOptions <FeedContext> feedContextOptions,
                    IFeedLoader feedLoader, IMapper mapper)
 {
     _feedContextOptions = feedContextOptions;
     _feedLoader         = feedLoader;
     _mapper             = mapper;
 }
        public async Task <ViewItem[]> GetCollectionNewsAsync(Guid id,
                                                              [FromServices] IFeedLoader feedLoader)
        {
            var collection = await _context.Collections.GetWithFeedsAsync(id);

            var feedsById = collection.Feeds.ToDictionary(f => f.Id);

            // Load in parallel
            var loading = await Timer.TimeAsync(async() =>
            {
                var newsByFeed = await _feedCache.GetFeedsAsync(feedsById.Keys.ToHashSet());
                return(await Task.WhenAll(feedsById.Values.Select(async feed =>
                {
                    var feedNews = newsByFeed.GetValueOrDefault(feed.Id);
                    if (feedNews == null)
                    {
                        feedNews = await feedLoader.LoadItemsAsync(feed);
                        await _feedCache.SetFeedAsync(feed.Id, feedNews);
                    }

                    return feedNews;
                })));
            });

            _logger.LogDebug($"Loaded all items for collection #{collection.Id} with {collection.Feeds.Count} feeds in {loading.ExecutionTime}.");

            return(loading.Result.SelectMany(ns => ns).Select(ViewItem.Create).ToArray());
        }
示例#3
0
 public FeedController(FeedService feedService, IFeedLoader feedLoader)
 {
     FeedService = feedService;
     FeedLoader = feedLoader;
 }
 public FeedLoaderController(ILogger <FeedLoaderController> logger, IFeedLoader feedLoader)
 {
     _logger     = logger;
     _feedLoader = feedLoader;
 }
示例#5
0
 public FeedGenerator(IFeedLoader feedLoader)
 {
     _feedLoader = feedLoader;
 }
示例#6
0
 public DataManager(IUpdateStrategy updateStrategy, IFeedLoader feedLoader)
 {
     _updateStrategy = updateStrategy;
     _feedLoader     = feedLoader;
 }