예제 #1
0
        public static List<StatusMessage> GetFriendItems(Core core, User owner, int limit, int page)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            List<long> friendIds = owner.GetFriendIds();
            List<StatusMessage> feedItems = new List<StatusMessage>();

            if (friendIds.Count > 0)
            {
                SelectQuery query = StatusMessage.GetSelectQueryStub(core, typeof(StatusMessage));
                query.AddSort(SortOrder.Descending, "status_time_ut");
                query.AddCondition("user_id", ConditionEquality.In, friendIds);
                query.LimitCount = limit;
                query.LimitStart = (page - 1) * limit;

                // if limit is less than 10, we will only get one for each member
                if (limit < 10)
                {
                    //query.AddGrouping("user_id");
                    // WHERE current
                }

                System.Data.Common.DbDataReader feedReader = core.Db.ReaderQuery(query);

                core.LoadUserProfiles(friendIds);

                while(feedReader.Read())
                {
                    feedItems.Add(new StatusMessage(core, core.PrimitiveCache[(long)feedReader["user_id"]], feedReader));
                }

                feedReader.Close();
                feedReader.Dispose();
            }

            return feedItems;
        }
예제 #2
0
        public static List<Action> GetItems(Core core, User owner, int currentPage, int perPage, long currentOffset, out bool moreContent)
        {
            double pessimism = 2.0;

            if (core == null)
            {
                throw new NullCoreException();
            }

            List<Action> feedItems = new List<Action>();
            moreContent = false;

            SelectQuery query = Action.GetSelectQueryStub(core, typeof(Action));
            query.AddSort(SortOrder.Descending, "action_time_ut");
            query.LimitCount = 64;

            List<long> friendIds = new List<long> { owner.Id };

            if (friendIds.Count > 0)
            {
                core.LoadUserProfiles(friendIds);

                query.AddCondition("action_primitive_id", ConditionEquality.In, friendIds);
                query.AddCondition("action_primitive_type_id", ItemKey.GetTypeId(core, typeof(User)));

                {
                    long lastId = 0;
                    QueryCondition qc1 = null;
                    if (currentOffset > 0)
                    {
                        qc1 = query.AddCondition("action_id", ConditionEquality.LessThan, currentOffset);
                    }
                    query.LimitCount = (int)(perPage * pessimism);

                    while (feedItems.Count <= perPage)
                    {
                        DataTable feedTable = core.Db.Query(query);

                        List<IPermissibleItem> tempMessages = new List<IPermissibleItem>();
                        List<Action> tempActions = new List<Action>();

                        if (feedTable.Rows.Count == 0)
                        {
                            break;
                        }

                        foreach (DataRow row in feedTable.Rows)
                        {
                            Action action = new Action(core, owner, row);
                            tempActions.Add(action);
                            core.ItemCache.RequestItem(action.ActionItemKey);
                            if (!action.ActionItemKey.Equals(action.InteractItemKey))
                            {
                                core.ItemCache.RequestItem(action.InteractItemKey);
                            }
                        }

                        foreach (Action action in tempActions)
                        {
                            tempMessages.Add(action.PermissiveParent);
                        }

                        core.AcessControlCache.CacheGrants(tempMessages);

                        foreach (Action action in tempActions)
                        {
                            if (action.PermissiveParent.Access.Can("VIEW"))
                            {
                                if (feedItems.Count == perPage)
                                {
                                    moreContent = true;
                                    break;
                                }
                                else
                                {
                                    feedItems.Add(action);
                                }
                            }
                            lastId = action.Id;
                        }

                        //query.LimitStart += query.LimitCount;
                        if (qc1 == null)
                        {
                            qc1 = query.AddCondition("action_id", ConditionEquality.LessThan, lastId);
                        }
                        else
                        {
                            qc1.Value = lastId;
                        }
                        query.LimitCount = (int)(query.LimitCount * pessimism);

                        if (moreContent)
                        {
                            break;
                        }
                    }
                }
            }

            return feedItems;
        }
예제 #3
0
        /// <summary>
        /// Retrieves a list of user tags for a given photo.
        /// </summary>
        /// <param name="core">Core token</param>
        /// <param name="galleryItem">Gallery item to retrieve user tags of</param>
        /// <returns>A list of user tags</returns>
        public static List<UserTag> GetTags(Core core, GalleryItem galleryItem)
        {
            List<UserTag> tags = new List<UserTag>();

            SelectQuery query = UserTag.GetSelectQueryStub(core, typeof(UserTag));
            query.AddCondition("gallery_item_id", galleryItem.ItemId);

            DataTable tagDataTable = core.Db.Query(query);

            List<long> userIds = new List<long>();
            foreach (DataRow dr in tagDataTable.Rows)
            {
                userIds.Add((long)dr["tag_user_id"]);
            }

            core.LoadUserProfiles(userIds);

            foreach (DataRow dr in tagDataTable.Rows)
            {
                tags.Add(new UserTag(core, galleryItem, dr));
            }

            return tags;
        }
예제 #4
0
        public static void LoadUserInfoCache(Core core, List<Comment> comments)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            List<long> userIds = GetUserIds(comments);

            core.LoadUserProfiles(userIds);
        }
예제 #5
0
        public static Dictionary<long, TopicPost> GetTopicLastPosts(Core core, List<ForumTopic> topics)
        {
            Dictionary<long, TopicPost> posts = new Dictionary<long, TopicPost>();
            Dictionary<long, ForumTopic> reverseLookup = new Dictionary<long, ForumTopic>();
            List<long> topicLastPostIds = new List<long>();

            foreach (ForumTopic topic in topics)
            {
                reverseLookup.Add(topic.LastPostId, topic);

                topicLastPostIds.Add(topic.LastPostId);
            }

            if (topicLastPostIds.Count > 0)
            {
                SelectQuery query = TopicPost.GetSelectQueryStub(core, typeof(TopicPost));
                query.AddCondition("post_id", ConditionEquality.In, topicLastPostIds);

                System.Data.Common.DbDataReader postsReader = core.Db.ReaderQuery(query);

                List<long> posterIds = new List<long>();

                while(postsReader.Read())
                {
                    long postId = (long)postsReader["post_id"];
                    TopicPost tp = new TopicPost(core, reverseLookup[postId], postsReader);
                    posterIds.Add(tp.UserId);
                    posts.Add(tp.Id, tp);
                }

                postsReader.Close();
                postsReader.Dispose();

                core.LoadUserProfiles(posterIds);
            }

            return posts;
        }
예제 #6
0
파일: Feed.cs 프로젝트: smithydll/boxsocial
        public static List<Action> GetItems(Core core, User owner, int currentPage, int perPage, long currentOffset, out bool moreContent)
        {
            long initTime = 0;

            double pessimism = 2.0;

            if (core == null)
            {
                throw new NullCoreException();
            }

            List<Action> feedItems = new List<Action>(perPage);
            moreContent = false;

            SelectQuery query = Action.GetSelectQueryStub(core, typeof(Action));
            query.AddSort(SortOrder.Descending, "action_time_ut");
            query.LimitCount = 64;

            List<long> friendIds = owner.GetFriendIds(100);
            if (core.Session.IsLoggedIn)
            {
                friendIds.Add(core.LoggedInMemberId);
            }

            // TODO: Add subscriptions to feed
            friendIds.AddRange(owner.GetSubscriptionUserIds(100));

            if (friendIds.Count > 0)
            {
                core.LoadUserProfiles(friendIds);

                query.AddCondition("action_primitive_id", ConditionEquality.In, friendIds);
                query.AddCondition("action_primitive_type_id", ItemKey.GetTypeId(core, typeof(User)));

                {
                    long lastId = 0;
                    QueryCondition qc1 = null;
                    if (currentOffset > 0)
                    {
                        qc1 = query.AddCondition("action_id", ConditionEquality.LessThan, currentOffset);
                    }
                    query.LimitCount = (int)(perPage * pessimism);

                    while (feedItems.Count <= perPage)
                    {
                        List<IPermissibleItem> tempMessages = new List<IPermissibleItem>(perPage);
                        List<Action> tempActions = new List<Action>(perPage);

                        System.Data.Common.DbDataReader feedReader = core.Db.ReaderQuery(query);

                        if (!feedReader.HasRows)
                        {
                            feedReader.Close();
                            feedReader.Dispose();
                            break;
                        }

                        while (feedReader.Read())
                        {
                            Action action = new Action(core, owner, feedReader);
                            tempActions.Add(action);
                        }

                        feedReader.Close();
                        feedReader.Dispose();

                        foreach (Action action in tempActions)
                        {
                            core.PrimitiveCache.LoadPrimitiveProfile(action.OwnerKey);
                            core.ItemCache.RequestItem(new ItemKey(action.ActionItemKey.GetType(core).ApplicationId, ItemKey.GetTypeId(core, typeof(ApplicationEntry))));
                        }

                        foreach (Action action in tempActions)
                        {
                            core.ItemCache.RequestItem(action.ActionItemKey);
                            if (!action.ActionItemKey.Equals(action.InteractItemKey))
                            {
                                core.ItemCache.RequestItem(action.InteractItemKey);
                            }
                        }

                        //HttpContext.Current.Response.Write("Time: " + (initTime / 10000000.0) + ", " + core.Db.GetQueryCount() + "<br />");
                        foreach (Action action in tempActions)
                        {
                            /*Stopwatch initTimer = new Stopwatch();
                            initTimer.Start();*/
                            tempMessages.Add(action.PermissiveParent);
                            /*initTimer.Stop();
                            initTime += initTimer.ElapsedTicks;

                            HttpContext.Current.Response.Write("Time: " + (initTime / 10000000.0) + ", " + action.ActionItemKey.ToString() + ", " + action.ActionItemKey.ApplicationId + ", " + core.Db.GetQueryCount() + "<br />");*/
                        }

                        if (tempMessages.Count > 0)
                        {
                            core.AcessControlCache.CacheGrants(tempMessages);
                        }

                        foreach (Action action in tempActions)
                        {
                            if (action.PermissiveParent.Access.Can("VIEW"))
                            {
                                if (feedItems.Count == perPage)
                                {
                                    moreContent = true;
                                    break;
                                }
                                else
                                {
                                    feedItems.Add(action);
                                }
                            }
                            lastId = action.Id;
                        }

                        //query.LimitStart += query.LimitCount;
                        if (qc1 == null)
                        {
                            qc1 = query.AddCondition("action_id", ConditionEquality.LessThan, lastId);
                        }
                        else
                        {
                            qc1.Value = lastId;
                        }
                        query.LimitCount = (int)(query.LimitCount * pessimism);

                        if (moreContent)
                        {
                            break;
                        }
                    }
                }
            }

            return feedItems;
        }