public async Task <IViewComponentResult> InvokeAsync() { var latestRanking = await _cache.GetOrCreateAsync("~RankSidebar", async e => { e.AbsoluteExpirationRelativeToNow = _cacheInterval; var latestData = await _db.HistoryRankings.AsNoTracking().Where(g => g.RankType != HistoryRanking.Type.RankDaily).GroupBy(g => g.RankType).SelectMany(g => g.OrderByDescending(d => d.RankDate).Take(5)) .Select(h => new { HistoryRanking = h, Deleted = !_db.Blogs.Any(b => b.BlogID == h.BlogID) }) .ToListAsync(); var name2nick = _blogUtil.GetNickNames(latestData.Select(r => r.HistoryRanking.Author)); return(latestData.Where(a => !a.Deleted).Select(h => new RankingDisplay { Author = name2nick[h.HistoryRanking.Author], BlogDate = h.HistoryRanking.BlogDate, BlogID = h.HistoryRanking.BlogID, BlogThumb = h.HistoryRanking.BlogThumb, BlogTitle = h.HistoryRanking.BlogTitle, BlogVisit = h.HistoryRanking.BlogVisit, BlogUrl = Url.Action("Details", "Blog", new { id = h.HistoryRanking.BlogID }), RankDate = h.HistoryRanking.RankDate, Rating = h.HistoryRanking.Rating, RankType = h.HistoryRanking.RankType, PostCount = h.HistoryRanking.PostCount }).ToList()); }); var ids = latestRanking.Select(c => c.BlogID); _visitCounter.PrepareBlogVisits(ids); var ratingUtil = ViewContext.HttpContext.RequestServices.GetService(typeof(RatingUtil)) as RatingUtil; ratingUtil.PrepareRatings(ids); return(View(latestRanking)); }
public void PrepareListCache(IEnumerable <Blog> list) { if (list == null || list.Count() == 0) { return; } var blogIds = list.Select(b => b.BlogID); _visitCounter.PrepareBlogVisits(blogIds); PreparePostCount(blogIds); RatingUtil.PrepareRatings(_cache, _db, blogIds); GetNickNames(list.Select(b => b.Author)); }