Exemplo n.º 1
0
        /// <summary>
        /// Query popular topics today
        /// </summary>
        /// <param name="timeRange">Time range</param>
        /// <param name="hostAppHandle">Hosting app handle: Master app or client app</param>
        /// <param name="cursor">Read cursor</param>
        /// <param name="limit">Number of items to return</param>
        /// <returns>Topic feed entities</returns>
        public async Task <IList <ITopicFeedEntity> > QueryPopularTopics(TimeRange timeRange, string hostAppHandle, int cursor, int limit)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.PopularTopics);

            RankFeedTable table   = this.tableStoreManager.GetTable(ContainerIdentifier.PopularTopics, TableIdentifier.PopularTopicsFeed) as RankFeedTable;
            string        feedKey = this.GetPopularTopicsFeedKey(timeRange, hostAppHandle);

            // convert our current API cursor (an int) to a CTStore cursor (a string).  Note that CTStore cursors
            // are offset by 1 from API cursors.  This hack will be removed when we change our API to use string-based
            // cursors.
            string ctCursor;

            if (cursor == 0)
            {
                ctCursor = null;
            }
            else
            {
                ctCursor = (cursor - 1).ToString();
            }

            var result = await store.QueryRankFeedReverseAsync(table, ContainerIdentifier.PopularTopics.ToString(), feedKey, ctCursor, limit);

            var convertedResults = result.Select(item => StoreSerializers.MinimalTopicRankFeedEntityDeserialize(item.ItemKey));

            return(convertedResults.ToList <ITopicFeedEntity>());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Query popular topics min score
        /// </summary>
        /// <param name="timeRange">Time range</param>
        /// <param name="hostAppHandle">Hosting app handle: Master app or client app</param>
        /// <returns>Score of the last entity in popular topics feed</returns>
        public async Task <long?> QueryPopularTopicsMinScore(TimeRange timeRange, string hostAppHandle)
        {
            CTStore store = await this.tableStoreManager.GetStore(ContainerIdentifier.PopularTopics);

            RankFeedTable table   = this.tableStoreManager.GetTable(ContainerIdentifier.PopularTopics, TableIdentifier.PopularTopicsFeed) as RankFeedTable;
            string        feedKey = this.GetPopularTopicsFeedKey(timeRange, hostAppHandle);

            // querying the rank feed in reverse order with a null cursor and a limit of 1 extracts the min entry in the feed
            var result = await store.QueryRankFeedReverseAsync(table, ContainerIdentifier.PopularTopics.ToString(), feedKey, null, 1);

            if (result.Count > 0)
            {
                return((long)result.First().Score);
            }

            return(null);
        }