当前位置: 首页>>代码示例>>C#>>正文


C# IReadOnlyCollection.Batch方法代码示例

本文整理汇总了C#中IReadOnlyCollection.Batch方法的典型用法代码示例。如果您正苦于以下问题:C# IReadOnlyCollection.Batch方法的具体用法?C# IReadOnlyCollection.Batch怎么用?C# IReadOnlyCollection.Batch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IReadOnlyCollection的用法示例。


在下文中一共展示了IReadOnlyCollection.Batch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateAnimeSeriesContractsAndSave

        private void UpdateAnimeSeriesContractsAndSave(ISessionWrapper session, IReadOnlyCollection<AnimeSeries> series)
        {
            _log.Info("Updating contracts for AnimeSeries");

            // Update batches of AnimeSeries contracts in parallel. Each parallel branch requires it's own session since NHibernate sessions aren't thread safe.
            // The reason we're doing this in parallel is because updating contacts does a reasonable amount of work (including LZ4 compression)
            Parallel.ForEach(series.Batch(DefaultBatchSize), new ParallelOptions { MaxDegreeOfParallelism = 4 },
                localInit: () => DatabaseFactory.SessionFactory.OpenStatelessSession(),
                body: (seriesBatch, state, localSession) =>
                    {
                        AnimeSeries.BatchUpdateContracts(localSession.Wrap(), seriesBatch);
                        return localSession;
                    },
                localFinally: localSession => { localSession.Dispose(); });

            _animeSeriesRepo.UpdateBatch(session, series);
            _log.Info("AnimeSeries contracts have been updated");
        }
开发者ID:ElementalCrisis,项目名称:jmmserver,代码行数:18,代码来源:AnimeGroupCreator.cs

示例2: UpdateAnimeGroupsAndTheirContracts

        private void UpdateAnimeGroupsAndTheirContracts(ISessionWrapper session, IReadOnlyCollection<AnimeGroup> groups)
        {
            _log.Info("Updating statistics and contracts for AnimeGroups");

            var allCreatedGroupUsers = new ConcurrentBag<List<AnimeGroup_User>>();

            // Update batches of AnimeGroup contracts in parallel. Each parallel branch requires it's own session since NHibernate sessions aren't thread safe.
            // The reason we're doing this in parallel is because updating contacts does a reasonable amount of work (including LZ4 compression)
            Parallel.ForEach(groups.Batch(DefaultBatchSize), new ParallelOptions { MaxDegreeOfParallelism = 4 },
                localInit: () => DatabaseFactory.SessionFactory.OpenStatelessSession(),
                body: (groupBatch, state, localSession) =>
                    {
                        var createdGroupUsers = new List<AnimeGroup_User>(groupBatch.Length);

                        // We shouldn't need to keep track of updates to AnimeGroup_Users in the below call, because they should have all been deleted,
                        // therefore they should all be new
                        AnimeGroup.BatchUpdateStats(groupBatch, watchedStats: true, missingEpsStats: true, createdGroupUsers: createdGroupUsers);
                        allCreatedGroupUsers.Add(createdGroupUsers);
                        AnimeGroup.BatchUpdateContracts(localSession.Wrap(), groupBatch, updateStats: true);

                        return localSession;
                    },
                localFinally: localSession => { localSession.Dispose(); });

            _animeGroupRepo.UpdateBatch(session, groups);
            _log.Info("AnimeGroup statistics and contracts have been updated");

            _log.Info("Creating AnimeGroup_Users and updating plex/kodi contracts");

            List<AnimeGroup_User> animeGroupUsers = allCreatedGroupUsers.SelectMany(groupUsers => groupUsers).ToList();

            // Insert the AnimeGroup_Users so that they get assigned a primary key before we update plex/kodi contracts
            _animeGroupUserRepo.InsertBatch(session, animeGroupUsers);
            // We need to repopulate caches for AnimeGroup_User and AnimeGroup because we've updated/inserted them
            // and they need to be up to date for the plex/kodi contract updating to work correctly
            _animeGroupUserRepo.Populate(session, displayname: false);
            _animeGroupRepo.Populate(session, displayname: false);

            // NOTE: There are situations in which UpdatePlexKodiContracts will cause database database writes to occur, so we can't
            // use Parallel.ForEach for the time being (If it was guaranteed to only read then we'd be ok)
            foreach (AnimeGroup_User groupUser in animeGroupUsers)
            {
                groupUser.UpdatePlexKodiContracts(session);
            }

            _animeGroupUserRepo.UpdateBatch(session, animeGroupUsers);
            _log.Info("AnimeGroup_Users have been created");
        }
开发者ID:ElementalCrisis,项目名称:jmmserver,代码行数:48,代码来源:AnimeGroupCreator.cs


注:本文中的IReadOnlyCollection.Batch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。