/// <summary> /// Gets the most published users. /// Measured by number of published stories per user /// </summary> /// <param name="hostID">The host ID.</param> /// <param name="userCount">The story count.</param> /// <param name="year">The year.</param> /// <param name="month">The month.</param> /// <param name="day">The day.</param> /// <returns></returns> public static Dictionary <string, int> GetMostPublishedUsers(int hostID, int userCount, int year, int?month, int?day) { string cacheKey = String.Format("Zeitgeist_MostPublishedUsers_{0}_{1}_{2}_{3}_{4}", hostID, userCount, year, month, day); CacheManager <string, Dictionary <string, int> > userListCache = GetMostPublishedUsersCache(); Dictionary <string, int> userList = userListCache[cacheKey]; if (userList == null) { //get all stories, then loop and make our own domain list Query qry = new Query(Story.Schema); qry.OrderBy = OrderBy.Desc(Story.Columns.UserID); qry.AddWhere(Story.Columns.IsSpam, false); qry.AddWhere(Story.Columns.IsPublishedToHomepage, true); qry.AddWhere(Story.Columns.HostID, hostID); qry.AddWhere(Story.Columns.CreatedOn, Comparison.GreaterOrEquals, StartingDate(year, month, day)); qry.AddWhere(Story.Columns.CreatedOn, Comparison.LessOrEquals, EndingDate(year, month, day)); StoryCollection stories = new StoryCollection(); stories.LoadAndCloseReader(Story.FetchByQuery(qry)); userList = new Dictionary <string, int>(); foreach (Story s in stories) { if (userList.ContainsKey(s.User.Username)) { userList[s.User.Username] += 1; } else { userList.Add(s.User.Username, 1); } } //sort and trim to storyCount List <KeyValuePair <string, int> > sortedPairs = new List <KeyValuePair <string, int> >(userList); sortedPairs.Sort( delegate(KeyValuePair <string, int> obj1, KeyValuePair <string, int> obj2) { return(obj2.Value.CompareTo(obj1.Value)); } ); userList.Clear();//clear and add top X values if (sortedPairs.Count < userCount) { userCount = sortedPairs.Count; } for (int i = 0; i < userCount; i++) { userList.Add(sortedPairs[i].Key, sortedPairs[i].Value); } userListCache.Insert(cacheKey, userList, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(userList); }
public static int GetPopularStoriesCount(int hostID, bool isPublished, StoryListSortBy sortBy) { string cacheKey = String.Format("Kick_PopularStoryCount_{0}_{1}_{2}", hostID, isPublished, sortBy); CacheManager <string, int?> countCache = GetCountCache(); int?count = countCache[cacheKey]; if (count == null) { count = Story.GetPopularStoriesCount(hostID, isPublished, sortBy); countCache.Insert(cacheKey, count, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(count.Value); }
public static int GetUserCommentsCount(string userIdentifier, int hostID) { string cacheKey = String.Format("Kick_Story_UserCommentsCount_{0}_{1}", userIdentifier, hostID); CacheManager <string, int?> countCache = GetCountCache(); int?count = countCache[cacheKey]; if (count == null) { count = Comment.GetUserCommentsCount(UserCache.GetUserID(userIdentifier), hostID); countCache.Insert(cacheKey, count, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(count.Value); }
public static int GetUserTaggedStoryCount(string tagIdentifier, int userID, int hostID) { string cacheKey = String.Format("Kick_UserTaggedStoryCount_{0}_{1}_{2}", tagIdentifier, userID, hostID); CacheManager <string, int?> countCache = GetCountCache(); int?count = countCache[cacheKey]; if (count == null) { count = Story.GetUserTaggedStoryCount(TagCache.GetTagID(tagIdentifier), userID, hostID); countCache.Insert(cacheKey, count, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(count.Value); }
public static CommentCollection GetComments(int storyID) { string cacheKey = GetCommentCacheKey(storyID); CacheManager <string, CommentCollection> commentCache = GetCommentCollectionCache(); CommentCollection comments = commentCache[cacheKey]; if (comments == null) { comments = Comment.FetchCommentsByStoryID(storyID); commentCache.Insert(cacheKey, comments, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(comments); }
public static StoryCollection GetUserSubmittedStories(string userIdentifier, int hostID, int pageNumber, int pageSize) { string cacheKey = String.Format("Kick_StoryTable_UserSubmitted_{0}_{1}_{2}_{3}", userIdentifier, hostID, pageNumber, pageSize); CacheManager <string, StoryCollection> storyCache = GetStoryCollectionCache(); StoryCollection stories = storyCache[cacheKey]; if (stories == null) { stories = Story.GetUserSubmittedStories(UserCache.GetUserID(userIdentifier), hostID, pageNumber, pageSize); storyCache.Insert(cacheKey, stories, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(stories); }
public static WeightedTagList GetHostTags(int hostID, DateTime createdOnLower, DateTime createdOnUpper) { string cacheKey = GetCacheKey("HostTags", hostID, createdOnLower, createdOnUpper); CacheManager <string, WeightedTagList> tagCache = GetWeightedTagListCache(); WeightedTagList tags = tagCache[cacheKey]; if (tags == null) { tags = Tag.FetchTags(hostID, createdOnLower, createdOnUpper).ToWeightedTagList(); //TODO: GJ: sort by alpha tagCache.Insert(cacheKey, tags, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(tags); }
private static ShoutCollection GetLatestShouts(int hostID, int?toUserID, int?chatID, int pageIndex, int pageSize) { string cacheKey = GetCacheKey(hostID, toUserID, chatID, pageIndex, pageSize); CacheManager <string, ShoutCollection> cache = GetShoutCache(); ShoutCollection shouts = cache[cacheKey]; if (shouts == null) { shouts = Shout.GetPage(hostID, toUserID, chatID, pageIndex, pageSize); cache.Insert(cacheKey, shouts, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(shouts); }
public static CategoryCollection GetCategories(int hostID) { CacheManager <string, CategoryCollection> categoryCache = GetCache(); string cacheKey = String.Format("KickCategories_{0}", hostID); CategoryCollection categories = categoryCache[cacheKey]; if (categories == null) { categories = new CategoryCollection(); SubSonic.OrderBy orderBy = SubSonic.OrderBy.Asc(Category.Columns.Name); categories.LoadAndCloseReader(Category.FetchByParameter(Category.Columns.HostID, hostID, orderBy)); categoryCache.Insert(cacheKey, categories, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(categories); }
public static WeightedTagList GetUserHostTags(int userID, int hostID) { string cacheKey = String.Format("UserHostTags_{0}_{1}", userID, hostID); CacheManager <string, WeightedTagList> tagCache = GetWeightedTagListCache(); WeightedTagList tags = tagCache[cacheKey]; if (tags == null) { tags = Tag.FetchTags(userID, hostID).ToWeightedTagList(); //TODO: GJ: sort by alpha tagCache.Insert(cacheKey, tags, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(tags); }
public static WeightedTagList GetStoryTags(int storyID) { string cacheKey = GetCacheKey("StoryTags", storyID); CacheManager <string, WeightedTagList> tagCache = GetWeightedTagListCache(); WeightedTagList tags = tagCache[cacheKey]; if (tags == null) { tags = Tag.FetchStoryTags(storyID).ToWeightedTagList(); //TODO: GJ: sort by alpha tagCache.Insert(cacheKey, tags, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(tags); }
public static ApiChat GetChat(int chatID) { string cacheKey = GetCacheKey(chatID); CacheManager <string, ApiChat> cache = GetCache(); ApiChat chat = cache[cacheKey]; if (chat == null) { chat = Chat.FetchByID(chatID).ToApi(true); cache.Insert(cacheKey, chat, 60, System.Web.Caching.CacheItemPriority.NotRemovable); } return(chat); }
public static UserActionCollection GetLatestUserActions(int hostID, int pageIndex, int pageSize, int?userID, Nullable <UserAction.ActionType> userActionType, int?storyID, int?chatID) { string cacheKey = GetCacheKey(hostID, pageIndex, pageSize, userID, userActionType, storyID, chatID); CacheManager <string, UserActionCollection> cache = GetUserActionCache(); UserActionCollection userActions = cache[cacheKey]; if (userActions == null) { userActions = UserAction.FetchCollection(hostID, pageIndex, pageSize, userID, userActionType, storyID, chatID); cache.Insert(cacheKey, userActions, 60, System.Web.Caching.CacheItemPriority.NotRemovable); } return(userActions); }
public static StoryCollection GetAllStories(bool isPublished, int hostID, int pageNumber, int pageSize) { pageSize = TrimPageSize(pageSize); string cacheKey = String.Format("StoryCollection_{0}_{1}_{2}_{3}", isPublished, hostID, pageNumber, pageSize); CacheManager <string, StoryCollection> storyCache = GetStoryCollectionCache(); StoryCollection stories = storyCache[cacheKey]; if (stories == null) { stories = Story.GetStoriesByIsPublishedAndHostID(isPublished, hostID, pageNumber, pageSize); storyCache.Insert(cacheKey, stories, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(stories); }
public static UserAlertMessageViewCollection GetUserAlerts(int userId) { string key = GetCacheKey(userId); CacheManager <string, UserAlertMessageViewCollection> cache = GetUserAlertMessageCache(); UserAlertMessageViewCollection alerts = cache[key]; if (alerts == null && userId != 0) { User user = User.FetchByID(userId); alerts = user.AlertMessages(); cache.Insert(key, alerts, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(alerts); }
public static StoryKickCollection GetUserStoryKicks(int userID) { string cacheKey = String.Format("Kick_StoryKickTable_{0}", userID); CacheManager <string, StoryKickCollection> storyKickCache = GetStoryKickCache(); StoryKickCollection storyKicks = storyKickCache[cacheKey]; if (storyKicks == null) { //TODO: get the latest n kicks for this userIdentifier storyKicks = StoryKick.FetchByUserID(userID); storyKickCache.Insert(cacheKey, storyKicks, CacheHelper.CACHE_DURATION_IN_SECONDS, System.Web.Caching.CacheItemPriority.NotRemovable); } return(storyKicks); }
public static StoryCollection GetPopularStories(int hostID, bool isPublished, StoryListSortBy sortBy, int pageNumber, int pageSize) { pageSize = TrimPageSize(pageSize); string cacheKey = String.Format("StoryCollection_{0}_{1}_{2}_{3}_{4}", hostID, isPublished, sortBy, pageNumber, pageSize); CacheManager <string, StoryCollection> storyCache = GetStoryCollectionCache(); StoryCollection stories = storyCache[cacheKey]; if (stories == null) { stories = Story.GetPopularStories(hostID, isPublished, sortBy, pageNumber, pageSize); storyCache.Insert(cacheKey, stories, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(stories); }
public static BlockedReferralCollection GetBlockedReferrals(int hostID) { CacheManager <string, BlockedReferralCollection> cache = GetBlockedReferralCache(); string key = GetCacheKey(hostID); if (cache[key] == null) { Query blockedReferralQuery = BlockedReferral.CreateQuery().WHERE(BlockedReferral.Columns.HostID, hostID).OR(BlockedReferral.Columns.HostID, Comparison.Is, null); BlockedReferralCollection blockedReferrals = new BlockedReferralCollection(); blockedReferrals.LoadAndCloseReader(blockedReferralQuery.ExecuteReader()); cache.Insert(key, blockedReferrals, 3600); } return(cache[key]); }
/// <summary> /// Gets the number of kicks. /// </summary> /// <param name="hostID">The host id.</param> /// <param name="year">The year.</param> /// <param name="month">The month.</param> /// <param name="day">The day.</param> /// <returns></returns> public static int GetNumberOfKicks(int hostID, int year, int?month, int?day) { string cacheKey = String.Format("Zeitgeist_KickCount_{0}_{1}_{2}_{3}", hostID, year, month, day); CacheManager <string, int?> countCache = GetStoryCountCache(); int?count = countCache[cacheKey]; if (count == null) { Query qry = new Query(StoryKick.Schema); qry.AddWhere(StoryKick.Columns.HostID, hostID); qry.AddWhere(StoryKick.Columns.CreatedOn, Comparison.GreaterOrEquals, StartingDate(year, month, day)); qry.AddWhere(StoryKick.Columns.CreatedOn, Comparison.LessOrEquals, EndingDate(year, month, day)); count = qry.GetRecordCount();// GetCount(StoryKick.Columns.StoryKickID); countCache.Insert(cacheKey, count.Value, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(count.Value); }
public static WeightedTagList GetTopHostTags(int hostID, int numberOfTags) { string cacheKey = String.Format("TopHostTags_{0}_{1}", hostID, numberOfTags); CacheManager <string, WeightedTagList> tagCache = GetWeightedTagListCache(); WeightedTagList tags = tagCache[cacheKey]; if (tags == null) { tags = GetHostTags(hostID); tags.Sort(new WeightedTagList.UsageCountComparer()); tags = tags.GetTopTags(numberOfTags); tags.Sort(new WeightedTagList.AlphabeticalComparer()); tagCache.Insert(cacheKey, tags, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(tags); }
public static CommentCollection GetUserComments(string userIdentifier, int hostID, int pageNumber, int pageSize) { string cacheKey = GetUserCommentsCacheKey(userIdentifier, hostID, pageNumber, pageSize); CacheManager <string, CommentCollection> commentCache = GetCommentCollectionCache(); CommentCollection comments = commentCache[cacheKey]; if (comments == null) { comments = Comment.GetUserComments(UserCache.GetUserID(userIdentifier), hostID, pageNumber, pageSize); if (comments != null) { commentCache.Insert(cacheKey, comments, CacheHelper.CACHE_DURATION_IN_SECONDS); } } return(comments); }
public static BannedUrlPatternCollection GetBannedUrlPatterns(int hostID) { CacheManager <string, BannedUrlPatternCollection> cache = GetBannedUrlPatternCache(); string key = GetCacheKey(hostID); if (cache[key] == null) { Query BannedUrlPatternQuery = BannedUrlPattern.CreateQuery().WHERE(BannedUrlPattern.Columns.HostId, hostID).OR(BannedUrlPattern.Columns.HostId, Comparison.Is, null); BannedUrlPatternCollection BannedUrlPatterns = new BannedUrlPatternCollection(); BannedUrlPatterns.LoadAndCloseReader(BannedUrlPatternQuery.ExecuteReader()); cache.Insert(key, BannedUrlPatterns, 3600); } return(cache[key]); }
public static int GetStoryCount(int hostID, bool isPublished, DateTime startDate, DateTime endDate) { string cacheKey = String.Format("Kick_StoryCount_{0}_{1}_{2}_{3}", isPublished, hostID, CacheHelper.DateTimeToCacheKey(startDate), CacheHelper.DateTimeToCacheKey(endDate)); CacheManager <string, int?> storyCountCache = GetCountCache(); int storyCount; if (storyCountCache.ContainsKey(cacheKey)) { storyCount = storyCountCache[cacheKey].Value; } else { storyCount = Story.GetStoryCount(hostID, isPublished, startDate, endDate); storyCountCache.Insert(cacheKey, storyCount, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(storyCount); }
public static int?GetTagID(string tagIdentifier) { string cacheKey = GetCacheKey("TagID", tagIdentifier); CacheManager <string, int?> tagCache = GetTagIDCache(); int?tagID = tagCache[cacheKey]; if (tagID == null) { Tag tag = Tag.FetchTagByIdentifier(tagIdentifier); if (tag != null) { tagID = tag.TagID; tagCache.Insert(cacheKey, tagID.Value, CacheHelper.CACHE_DURATION_IN_SECONDS); } } return(tagID); }
public static int GetUserID(string username) { CacheManager <string, int?> userIDCache = GetUserIDCache(); string cacheKey = "GetUserID_" + username; int?userID = userIDCache[cacheKey]; if (!userID.HasValue) { User user = User.FetchUserByUsername(username); if (user == null) { throw new ArgumentException("Invalid username"); } userID = user.UserID; userIDCache.Insert(cacheKey, userID, CacheHelper.CACHE_DURATION_IN_SECONDS, System.Web.Caching.CacheItemPriority.NotRemovable); } return(userID.Value); }
/// <summary> /// Searches the index for stories kicked by a given user /// </summary> /// <param name="query"></param> /// <param name="username"></param> /// <param name="hostId"></param> /// <param name="page"></param> /// <param name="pageSize"></param> /// <returns></returns> public static StoryCollection GetStoryCollectionSearchResultsByUser(string query, string username, string sortField, bool sortReversed, int hostId, int page, int pageSize) { string cacheKey = string.Format("SearchUserStoryCollection_{0}_{1}_{2}_{3}_{4}_{5}_{6}", CleanUpQuery(query), hostId, page, pageSize, username, sortField, sortReversed); string cacheCountKey = string.Format("SearchUserStoryCollectionCount_{0}_{1}_{2}", CleanUpQuery(query), hostId, username); CacheManager <string, StoryCollection> cache = GetSearchStoryCollectionCache(); StoryCollection results = cache[cacheKey]; if (results == null) { int totalNumberResults = 0; SearchQuery searchQuery = new SearchQuery(); results = searchQuery.SearchIndex(hostId, query, username, page, pageSize, sortField, sortReversed, out totalNumberResults); if (results != null) { cache.Insert(cacheKey, results, CacheHelper.CACHE_DURATION_IN_SECONDS); } //add to the cache containing the search results counts, we dont want to have to call the //the search twice since we already have this value in this method call. CacheManager <string, int?> cacheCount = GetSearchStoryCountCache(); if (cacheCount.ContainsKey(cacheCountKey)) { cacheCount.Remove(cacheCountKey); } cacheCount.Insert(cacheCountKey, totalNumberResults, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(results); }
public static UserCollection GetOnlineUsers(int minutesSinceLastActive, int hostID, User userProfile) { string cacheKey = String.Format("OnlineUsers_{0}_{1}", minutesSinceLastActive, hostID); CacheManager <string, UserCollection> userCollectionCache = GetUserCollectionCache(); UserCollection users = userCollectionCache[cacheKey]; if (users == null) { users = User.FetchOnlineUsers(minutesSinceLastActive, hostID); userCollectionCache.Insert(cacheKey, users, 60, System.Web.Caching.CacheItemPriority.NotRemovable); } // If current user has permissions show all online users if (userProfile.IsModerator || userProfile.IsAdministrator) { return(users); } // Otherwise show only users who choose to appear online users.RemoveAll(delegate(User user) { return(!user.AppearOnline); }); return(users); }
public static StoryCollection GetSimilarStoryCollection(int hostId, int storyId) { string cacheKey = string.Format("SimilarStoryCollection_{0}_{1}", storyId, hostId); CacheManager <string, StoryCollection> cache = GetSimilarStoriesCache(); StoryCollection results = cache[cacheKey]; if (results == null) { SimilarStories similarStories = new SimilarStories(); results = similarStories.Find(hostId, storyId); if (results != null) { cache.Insert(cacheKey, results, CacheHelper.CACHE_DURATION_IN_SECONDS); } } return(results); }
/// <summary> /// Gets the most kicked stories. /// </summary> /// <param name="hostID">The host ID.</param> /// <param name="storyCount">The story count.</param> /// <param name="year">The year.</param> /// <param name="month">The month.</param> /// <param name="day">The day.</param> /// <returns></returns> public static StoryCollection GetMostPopularStories(int hostID, int storyCount, int year, int?month, int?day) { string cacheKey = String.Format("Zeitgeist_MostPopular_{0}_{1}_{2}_{3}_{4}", hostID, storyCount, year, month, day); CacheManager <string, StoryCollection> storyCache = GetStoryCollectionCache(); StoryCollection stories = storyCache[cacheKey]; if (stories == null) { Query qry = new Query(Story.Schema); qry.Top = storyCount.ToString(); qry.OrderBy = OrderBy.Desc(Story.Columns.KickCount); qry.AddWhere(Story.Columns.IsSpam, false); qry.AddWhere(Story.Columns.HostID, hostID); qry.AddWhere(Story.Columns.CreatedOn, Comparison.GreaterOrEquals, StartingDate(year, month, day)); qry.AddWhere(Story.Columns.CreatedOn, Comparison.LessOrEquals, EndingDate(year, month, day)); qry.AddWhere(Story.Columns.KickCount, Comparison.GreaterOrEquals, 1); stories = new StoryCollection(); stories.LoadAndCloseReader(Story.FetchByQuery(qry)); storyCache.Insert(cacheKey, stories, CacheHelper.CACHE_DURATION_IN_SECONDS); } return(stories); }
public static Story GetStory(string storyIdentifier, int hostID) { string cacheKey = GetStoryCacheKey(storyIdentifier); CacheManager <string, Story> storyCache = GetStoryCache(); Story story = storyCache[cacheKey]; if (story == null) { story = Story.FetchStoryByIdentifier(storyIdentifier); if (story != null) { storyCache.Insert(cacheKey, story, CacheHelper.CACHE_DURATION_IN_SECONDS); } } if (hostID != story.HostID) { throw new ArgumentException("The story does not belong to the host"); } return(story); }