private static void InitCache(this IDatabase db) { JMMUserRepository.InitCache(); AniDB_AnimeRepository.InitCache(); VideoInfoRepository.InitCache(); VideoLocalRepository.InitCache(); VideoLocal_UserRepository.InitCache(); List <GroupFilter> recalc = GroupFilterRepository.InitCache(); AnimeEpisodeRepository.InitCache(); AnimeEpisode_UserRepository.InitCache(); AnimeSeriesRepository.InitCache(); AnimeSeries_UserRepository.InitCache(); AnimeGroupRepository.InitCache(); AnimeGroup_UserRepository.InitCache(); GroupFilterRepository.InitCacheSecondPart(recalc); DatabaseFixes.ExecuteDatabaseFixes(); db.CleanUpMemory(); }
/// <summary> /// Update the stats for this group based on the child series /// Assumes that all the AnimeSeries have had their stats updated already /// </summary> public void UpdateStats(bool watchedStats, bool missingEpsStats) { List <AnimeSeries> seriesList = GetAllSeries(); JMMUserRepository repUsers = new JMMUserRepository(); List <JMMUser> allUsers = repUsers.GetAll(); if (watchedStats) { foreach (JMMUser juser in allUsers) { AnimeGroup_User userRecord = GetUserRecord(juser.JMMUserID); if (userRecord == null) { userRecord = new AnimeGroup_User(juser.JMMUserID, this.AnimeGroupID); } // reset stats userRecord.WatchedCount = 0; userRecord.UnwatchedEpisodeCount = 0; userRecord.PlayedCount = 0; userRecord.StoppedCount = 0; userRecord.WatchedEpisodeCount = 0; userRecord.WatchedDate = null; foreach (AnimeSeries ser in seriesList) { AnimeSeries_User serUserRecord = ser.GetUserRecord(juser.JMMUserID); if (serUserRecord != null) { userRecord.WatchedCount += serUserRecord.WatchedCount; userRecord.UnwatchedEpisodeCount += serUserRecord.UnwatchedEpisodeCount; userRecord.PlayedCount += serUserRecord.PlayedCount; userRecord.StoppedCount += serUserRecord.StoppedCount; userRecord.WatchedEpisodeCount += serUserRecord.WatchedEpisodeCount; if (serUserRecord.WatchedDate.HasValue) { if (userRecord.WatchedDate.HasValue) { if (serUserRecord.WatchedDate > userRecord.WatchedDate) { userRecord.WatchedDate = serUserRecord.WatchedDate; } } else { userRecord.WatchedDate = serUserRecord.WatchedDate; } } } } // now update the stats for the groups logger.Trace("Updating stats for {0}", this.ToString()); AnimeGroup_UserRepository rep = new AnimeGroup_UserRepository(); rep.Save(userRecord); } } if (missingEpsStats) { this.MissingEpisodeCount = 0; this.MissingEpisodeCountGroups = 0; foreach (AnimeSeries ser in seriesList) { this.MissingEpisodeCount += ser.MissingEpisodeCount; this.MissingEpisodeCountGroups += ser.MissingEpisodeCountGroups; } AnimeGroupRepository repGrp = new AnimeGroupRepository(); repGrp.Save(this); } }
public AnimeGroup_User GetUserRecord(ISession session, int userID) { AnimeGroup_UserRepository repUser = new AnimeGroup_UserRepository(); return(repUser.GetByUserAndGroupID(session, userID, this.AnimeGroupID)); }