Пример #1
0
        public static bool AddUserTag(User user, int tagId, List <int> ignoredTagIds = null)
        {
            return(Retry3TimesForTimeout(() =>
            {
                var tagArticles = CacheClient.InMemoryCache.GetOrAdd <List <Article> >("articles" + tagId, CachePeriod.ForHours(1),
                                                                                       () => FeedService.GetArticlesPublishedAfterForTag(DateTime.Now.Date.AddMonths(-1), tagId));
                var db = GetDatabase();

                if (ignoredTagIds != null && ignoredTagIds.Count > 0)
                {
                    foreach (var ignoredTagId in ignoredTagIds)
                    {
                        var tagIgnoredArticles = CacheClient.InMemoryCache.GetOrAdd <List <Article> >("ingored-articles" + string.Join(",", ignoredTagIds), CachePeriod.ForHours(1),
                                                                                                      () => FeedService.GetArticlesPublishedAfterForTag(DateTime.Now.Date.AddMonths(-1), ignoredTagId));
                        tagArticles = tagArticles.FindAll(a => !tagIgnoredArticles.Select(ta => ta.Id).Contains(a.Id));
                    }
                }

                if (user.HideVisitedArticles)
                {
                    var visitedArticleIds = FeedService.GetArticlesVisitedAndPublishedAfter(user.Id, DateTime.Now.Date.AddMonths(-1));
                    tagArticles = tagArticles.FindAll(a => !visitedArticleIds.Contains(a.Id));
                }

                db.SortedSetAdd(GetWeekKey(user.Id), tagArticles.FindAll(a => a.Published >= DateTime.Now.Date.AddDays(-7))
                                .Select(a => new SortedSetEntry(a.Id, a.LikesCount))
                                .ToArray());
                db.SortedSetAdd(GetMonthKey(user.Id), tagArticles.FindAll(a => a.Published < DateTime.Now.Date.AddDays(-7) &&
                                                                          a.Published >= DateTime.Now.Date.AddMonths(-1))
                                .Select(a => new SortedSetEntry(a.Id, a.LikesCount))
                                .ToArray());
                //AddUser(user);
                return true;
            }, exceptionMessage: "AddUserTag:user:"******" tag:" + tagId + ":ignoredtagIds:" + ignoredTagIds.ToXml()));
        }
Пример #2
0
 public static List <User> GetUsers()
 {
     return(Retry3TimesForTimeout(() =>
     {
         return CacheClient.InMemoryCache.GetOrAdd <List <User> >(GetUsersKey(), CachePeriod.ForHours(1), () =>
         {
             var db = GetDatabase();
             var usersSet = db.SortedSetRangeByScore(GetUsersKey(), order: Order.Descending);
             var users = new List <User>();
             foreach (var user in usersSet)
             {
                 users.Add(GetUser((int)user));
             }
             return users;
         });
     }, exceptionMessage: "GetUsers"));
 }