Esempio n. 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;
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
        public static List<Action> GetNewerItems(Core core, User owner, long newerThanOffset)
        {
            List<Action> feedItems = new List<Action>(10);

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

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

            friendIds.AddRange(owner.GetSubscriptionUserIds(100));

            QueryCondition qc1 = query.AddCondition("action_id", ConditionEquality.GreaterThan, newerThanOffset);

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

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

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

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

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

            foreach (Action action in tempActions)
            {
                core.ItemCache.RequestItem(new ItemKey(action.ActionItemKey.GetType(core).ApplicationId, ItemType.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);
                }
            }

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

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

            foreach (Action action in tempActions)
            {
                if (action.PermissiveParent.Access.Can("VIEW"))
                {
                    if (feedItems.Count == 10)
                    {
                        break;
                    }
                    else
                    {
                        feedItems.Add(action);
                    }
                }
            }

            return feedItems;
        }