Esempio n. 1
0
        public IEnumerable <int> StoreStats(IEnumerable <int> threadIds, CancellationToken cancelToken)
        {
            using (var wrapper = new TransactionWrapper(cancelToken))
            {
                var db = wrapper.Connection;

                // thread stats
                var missingThreadIdList = new List <int>();
                var forumIdList         = new List <int>();
                foreach (var threadId in threadIds)
                {
                    var threadPost = db.Find <DbPost>(threadId);
                    if (threadPost == null)
                    {
                        missingThreadIdList.Add(threadId);
                        continue;
                    }
                    var threadReplies = db.Posts.Where(p => p.ThreadId == threadId);
                    var thread        = db.Find <DbThread>(threadId) ?? new DbThread
                    {
                        ThreadId = threadId,
                    };

                    thread.PostCount = threadReplies.Count();
                    var threadViewed = (thread.Viewed ?? DateTime.MinValue);
                    thread.NewPostCount = threadReplies.Count(p => p.Posted > threadViewed);
                    db.Threads.AddOrUpdate(thread, t => t.ThreadId);

                    threadPost.Updated = threadReplies.Any() ?
                                         DbPost.MostRecent(threadReplies.Max(p => p.Updated), threadReplies.Max(p => p.Posted)) :
                                         threadPost.Updated ?? threadPost.Posted;
                    //db.Update(threadPost);

                    forumIdList.Add(threadPost.ForumId);
                }

                // forum stats
                var forumIds = forumIdList.Distinct().ToArray();
                foreach (var forumId in forumIds)
                {
                    var forum      = db.Forums.Find(forumId);
                    var forumPosts = db.Posts.Where(p => p.ForumId == forumId);

                    forum.Fetched   = DateTime.UtcNow;
                    forum.PostCount = forumPosts.Count(p => p.ThreadId == null);
                    if (forumPosts.Any())
                    {
                        forum.Posted = DbPost.MostRecent(forumPosts.Max(p => p.Updated), forumPosts.Max(p => p.Posted));
                    }
                    //db.Update(forum);
                }

                return(missingThreadIdList.ToArray());
            }
        }
Esempio n. 2
0
        public void StoreDirectory(ForumResponse directory, CancellationToken cancelToken)
        {
            var groups = mapper.Map <IEnumerable <DbGroup> >(directory.groupList);
            var forums = mapper.Map <IEnumerable <DbForum> >(directory.forumList);

            using (var wrapper = new TransactionWrapper(cancelToken))
            {
                var db = wrapper.Connection;
                db.Groups.AddOrUpdateRange(groups, g => g.Id);
                db.Forums.AddOrUpdateRange(forums, f => f.Id);
            }
        }
Esempio n. 3
0
        public void StoreArchives(TopicResponse archives, CancellationToken cancelToken)
        {
            using (var wrapper = new TransactionWrapper(cancelToken))
            {
                var db = wrapper.Connection;

                StoreRatings(db, archives.Rating);

                var arcPosts = mapper.Map <IEnumerable <DbPost> >(archives.Messages);
                db.Posts.AddOrUpdateRange(arcPosts, p => p.Id);
            }
        }