Пример #1
0
        private void ExecuteIndexer(IVulcanIndexer indexer, IVulcanFeatureCacheScope isCacheScopeFeature, ref int totalIndexedCount)
        {
            var pocoIndexer = indexer as IVulcanPocoIndexer;
            var cmsIndexer  = indexer as IVulcanContentIndexer;

            if (pocoIndexer?.IncludeInDefaultIndexJob == true)
            {
                var alias = _vulcanIndexContentJobSettings.EnableAlwaysUp ? VulcanHelper.TempAlias : null;
                _vulcanPocoIndexHandler.Index(pocoIndexer, OnStatusChanged, ref totalIndexedCount, ref _stopSignaled, alias);
            }
            else if (cmsIndexer != null) // default episerver content
            {
                var contentReferences = _vulcanSearchContentLoader.GetSearchContentReferences(cmsIndexer).ToList();
                var contentRecord     = 0;
                var totalCount        = contentReferences.Count;

                if (_vulcanIndexContentJobSettings.EnableParallelContent)
                {
                    var thisIndexerCount = 0;

                    Parallel.ForEach(contentReferences, new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = _vulcanIndexContentJobSettings.ParallelDegree
                    }, contentReference =>
                    {
                        if (_stopSignaled)
                        {
                            return;
                        }
                        if (IndexContent(contentReference, contentRecord, cmsIndexer, isCacheScopeFeature, totalCount))
                        {
                            Interlocked.Increment(ref thisIndexerCount);
                        }

                        Interlocked.Increment(ref contentRecord);
                    });

                    Interlocked.Exchange(ref totalIndexedCount, totalIndexedCount + thisIndexerCount);
                }
                else
                {
                    foreach (var contentReference in contentReferences)
                    {
                        if (IndexContent(contentReference, contentRecord, cmsIndexer, isCacheScopeFeature, totalCount))
                        {
                            totalIndexedCount++;
                        }

                        contentRecord++;
                    }
                }
            }
        }
Пример #2
0
        private IContent LoadWithCacheScope(ContentReference c, IVulcanFeatureCacheScope vulcanFeatureCache)
        {
            if (vulcanFeatureCache?.Enabled != true)
            {
                return(_vulcanSearchContentLoader.GetContent(c));
            }

            using (new ContentCacheScope {
                SlidingExpiration = vulcanFeatureCache.CacheDuration
            })
            {
                return(_vulcanSearchContentLoader.GetContent(c));
            }
        }
Пример #3
0
        private bool IndexContent(ContentReference contentReference, int contentRecord, IVulcanContentIndexer cmsIndexer, IVulcanFeatureCacheScope isCacheScopeFeature, int totalCount)
        {
            if
            (
                isCacheScopeFeature?.Enabled != true &&
                cmsIndexer is IVulcanContentIndexerWithCacheClearing cacheClearingIndexer &&
                cacheClearingIndexer.ClearCacheItemInterval >= 0
            )
            {
                if (contentRecord % cacheClearingIndexer.ClearCacheItemInterval == 0)
                {
                    cacheClearingIndexer.ClearCache();
                }
            }

            // only update this every 100 records (reduce load on db)
            if (contentRecord % 100 == 0)
            {
                OnStatusChanged($"{cmsIndexer.IndexerName} indexing item {contentRecord + 1} of {totalCount} items of {cmsIndexer.GetRoot().Value} content");
            }

            IContent content;

            try
            {
                content = LoadWithCacheScope(contentReference, isCacheScopeFeature);
            }
            catch (OutOfMemoryException)
            {
                Logger.Warning($"Vulcan encountered an OutOfMemory exception, attempting again to index content item {contentReference}...");

                // try once more
                try
                {
                    // ReSharper disable once RedundantAssignment
                    content = LoadWithCacheScope(contentReference, isCacheScopeFeature);
                }
                catch (Exception eNested)
                {
                    Logger.Error($"Vulcan could not recover from an out of memory exception when it tried again to index content item  {contentReference} : {eNested}");
                }

                return(false);
            }
            catch (Exception eOther)
            {
                Logger.Error($"Vulcan could not index content item {contentReference} : {eOther}");

                return(false);
            }

            if (content == null)
            {
                Logger.Error($"Vulcan could not index content item {contentReference}: content was null");

                return(false);
            }

            Logger.Information($"Vulcan indexed content with reference: {contentReference} and name: {content.Name}");

            _vulcanHandler.IndexContentEveryLanguage(content, _vulcanIndexContentJobSettings.EnableAlwaysUp ? VulcanHelper.TempAlias : null);

            return(true);
        }