public PaginatedInterestCard GetUserInterests(string currUserId, PaginatedRequest req) { PaginatedInterestCard ret = new PaginatedInterestCard(); userGroupFollowIds = _userLikesCacheService.GetUserFollowingGroupsIds(currUserId); if (userGroupFollowIds == null || userGroupFollowIds.Count() == 0) { userGroupFollowIds = _userLikesDataService.GetUserFollowingGroups(currUserId, 30); _userLikesCacheService.SetUserFollowingGroupsIds(currUserId, userGroupFollowIds, 20); } int total = userGroupFollowIds.Count(); if (total < 1) { return(ret); } int[] paginatedIds = userGroupFollowIds.Skip((req.PageIndex - 1) * req.PageSize).Take(req.PageSize).ToArray(); ret.Entities = _context.Set <Group>().AsNoTracking() .Select(f => new { Entity = f, f.ProfileImage }) .Where(p => paginatedIds.Contains(p.Entity.Id)) .Select(p => new InterestCard() { AlphaColor = p.Entity.ColorAlpha, UrlKey = p.Entity.UrlKey, Id = p.Entity.Id, Name = p.Entity.Name, IsCurrentUserFollowing = true, ProfileImage = p.Entity.ProfileImage.SmallPath }).ToPaginatedList(req.PageIndex, req.PageSize, total); return(ret); }
public PaginatedInterestCard GetExploreInterests(PaginatedLangRequest req, string currUserId) { userFollowedInterest = _userLikesCacheService.GetUserFollowingGroupsIds(currUserId); if (userFollowedInterest == null || userFollowedInterest.Count() == 0) { userFollowedInterest = _userLikesDataService.GetUserFollowingGroups(currUserId, 5); _userLikesCacheService.SetUserFollowingGroupsIds(currUserId, userFollowedInterest, 20); } PaginatedInterestCard ret = new PaginatedInterestCard(); int[] langCodeTrendingInterestIds = _exploreCacheService.GetExploreInterestIds(req.LangCode, req.PageIndex); int? totalGroupCount = _commonCacheService.GetTotalGroupCount(); if (!totalGroupCount.HasValue) { totalGroupCount = _context.Set <Group>().Count(); _commonCacheService.SetTotalGroupCount(totalGroupCount.Value, 10); } if (langCodeTrendingInterestIds == null || langCodeTrendingInterestIds.Count() == 0) { // Order by follower count langCodeTrendingInterestIds = _context.Set <Group>() .AsNoTracking() .SelectMany(a => a.UsersFollowing) .GroupBy(t => t.GroupId, (k, g) => new { GroupId = k, gs = g, Count = g.Count(q => q.GroupFollowState == GroupFollowState.Followed) }) .OrderByDescending(g => g.Count) .Select(f => f.GroupId) .Distinct() .Skip((req.PageIndex - 1) * req.PageSize) .Take(req.PageSize) .ToArray(); if (langCodeTrendingInterestIds != null) { if (langCodeTrendingInterestIds.Length > req.PageSize) { _exploreCacheService.SetExploreInterestIds(req.LangCode, req.PageIndex, langCodeTrendingInterestIds, 60 * 24); } } } ret.Entities = _context.Set <Group>().AsNoTracking() .Select(p => new { Entity = p, Image = p.ProfileImage, p.CoverImage }) .Where(p => langCodeTrendingInterestIds.Contains(p.Entity.Id)) .Select(p => new InterestCard() { AlphaColor = p.Entity.ColorAlpha, Id = p.Entity.Id, Name = p.Entity.Name, UrlKey = p.Entity.UrlKey, IsCurrentUserFollowing = userFollowedInterest.Contains(p.Entity.Id), ProfileImage = p.Image.SmallPath, CoverImage = p.CoverImage.ThumbPath }) .ToPaginatedList(req.PageIndex, req.PageSize, totalGroupCount.Value); return(ret); }