Skip to content

Commit

Permalink
move DnnBusinessController to right namespace part of #1802
Browse files Browse the repository at this point in the history
and prevent search index from logging more than 10 issues
  • Loading branch information
iJungleboy committed Jan 19, 2021
1 parent 5c4fb7d commit cecc33e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<desktopModule>
<moduleName>2sxc</moduleName>
<foldername>ToSIC_SexyContent</foldername>
<businessControllerClass>ToSic.SexyContent.Environment.Dnn7.DnnBusinessController</businessControllerClass>
<businessControllerClass>ToSic.Sxc.Dnn.DnnBusinessController</businessControllerClass>
<supportedFeatures>
<supportedFeature type="Searchable" />
<supportedFeature type="Upgradeable" />
Expand Down Expand Up @@ -97,7 +97,7 @@
</processorType>
<processorCommand>UpgradeModule</processorCommand>
<attributes>
<businessControllerClass>ToSic.SexyContent.Environment.Dnn7.DnnBusinessController</businessControllerClass>
<businessControllerClass>ToSic.Sxc.Dnn.DnnBusinessController</businessControllerClass>
<desktopModuleID>[DESKTOPMODULEID]</desktopModuleID>
<upgradeVersionsList>01.00.00,08.11.00,08.12.00,09.00.00,09.00.01,09.00.02,09.01.00,09.01.02,09.01.03,09.02.00,09.03.00,09.03.01,09.03.02,09.03.03,09.04.00,09.04.01,09.04.02,09.04.03,09.05.00,09.05.01,09.05.02,09.06.00,09.06.01,09.07.00,09.08.00,09.09.00,09.10.00,09.11.00,09.11.01,09.12.00,09.13.00,09.14.00,09.20.00,09.21.00,09.22.00,09.23.00,09.30.00,09.31.00,09.32.00,09.33.00,09.35.00,09.40.00,09.40.01,09.41.00,09.42.00,09.43.00,09.43.01,10.00.00,10.01.00,10.02.00,10.03.00,10.04.00,10.05.00,10.06.00,10.07.00,10.08.00,10.09.00,10.09.01,10.20.00,10.20.01,10.20.02,10.20.03,10.20.04,10.20.05,10.21.00,10.22.00,10.23.00,10.24.00,10.25.00,10.25.02,10.25.03,10.26.00,10.27.00,10.27.01,10.28.00,10.30.00,11.00.00,11.01.00,11.02.00,11.03.00,11.04.00,11.05.00,11.06.00,11.06.01,11.07.00,11.07.01,11.07.02,11.07.03,11.10.00,11.10.01,11.11.00,11.11.01,11.11.02,11.11.03</upgradeVersionsList>
</attributes>
Expand Down Expand Up @@ -564,7 +564,7 @@
<desktopModule>
<moduleName>2sxc-app</moduleName>
<foldername>ToSIC_SexyContent</foldername>
<businessControllerClass>ToSic.SexyContent.Environment.Dnn7.DnnBusinessController</businessControllerClass>
<businessControllerClass>ToSic.Sxc.Dnn.DnnBusinessController</businessControllerClass>
<supportedFeatures>
<supportedFeature type="Searchable" />
<supportedFeature type="Upgradeable" />
Expand Down
6 changes: 4 additions & 2 deletions Src/Dnn/ToSic.Sxc.Dnn/2sxc Dnn.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<Compile Include="Dnn\Adam\DnnAdamFileSystem.cs" />
<Compile Include="Dnn\Web\DnnLinkHelper.cs" />
<Compile Include="Dnn\Run\DnnModuleUpdater.cs" />
<Compile Include="Environment\Dnn7\DnnBusinessController.cs" />
<Compile Include="Dnn\DnnBusinessController.cs" />
<Compile Include="Dnn\Run\DnnModule.cs" />
<Compile Include="Dnn\Run\DnnPermissionCheck.cs" />
<Compile Include="Dnn\Run\DnnSite.cs" />
Expand Down Expand Up @@ -184,6 +184,8 @@
<None Include="packages.config" />
<None Include="Dnn\Search\readme.md" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="Environment\Dnn7\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Threading;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Search.Entities;
using ToSic.Eav.Apps;
using ToSic.Eav.Logging;
using ToSic.Eav.Logging.Simple;
using ToSic.Eav.Plumbing;
Expand All @@ -11,8 +11,7 @@
using ToSic.Sxc.Dnn.Run;
using ToSic.Sxc.Search;

// ReSharper disable once CheckNamespace
namespace ToSic.SexyContent.Environment.Dnn7
namespace ToSic.Sxc.Dnn
{
/// <summary>
/// This is the connector-class which DNN consults when it needs to know things about a module
Expand Down Expand Up @@ -104,10 +103,35 @@ public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo modu
}
catch (Exception e)
{
throw new SearchIndexException(moduleInfo, e);
var errCount = ErrorCount++;
if (errCount < 10)
throw new SearchIndexException(moduleInfo, e, nameof(DnnBusinessController));
if (errCount == 10)
throw new SearchIndexException(moduleInfo,
new Exception("Hit 10 SearchIndex exceptions in 2sxc modules, will stop reporting them to not flood the error log."),
nameof(DnnBusinessController));
// ignore errors after 10
return new List<SearchDocument>();
}
}

#endregion

#region Count Exceptions, don't overload the error log

private const string ThreadSlotErrorCount = "2sxcSearchErrorCount";

private int ErrorCount
{
get
{
var count = Thread.GetData(Thread.GetNamedDataSlot(ThreadSlotErrorCount));
if (count == null) return 0;
return (int) count;
}
set => Thread.SetData(Thread.GetNamedDataSlot(ThreadSlotErrorCount), value);
}

#endregion
}
}
9 changes: 3 additions & 6 deletions Src/Dnn/ToSic.Sxc.Dnn/Dnn/Search/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public IList<SearchDocument> GetModifiedSearchDocuments(IModule module, DateTime

if (appId == AppConstants.AppIdNotFound || appId == Eav.Constants.NullId) return searchDocuments;

// Since Portal-Settings.Current is null, instantiate with modules' portal id (which can be a different portal!)
//var portalSettings = new PortalSettings(dnnModule.OwnerPortalID);
var site = new DnnSite().TrySwap(dnnModule);//.Swap(portalSettings);
var site = new DnnSite().TrySwap(dnnModule);

// Ensure cache builds up with correct primary language
var cache = State.Cache;
Expand All @@ -61,7 +59,6 @@ public IList<SearchDocument> GetModifiedSearchDocuments(IModule module, DateTime
var dnnContext = Eav.Factory.StaticBuild<IContextOfBlock>().Init(dnnModule, Log);
var modBlock = _serviceProvider.Build<BlockFromModule>()
.Init(dnnContext, Log);
//.Init(DnnContextOfBlock.Create(site, container, Eav.Factory.GetServiceProvider()), Log);

var language = dnnModule.CultureCode;

Expand Down Expand Up @@ -99,7 +96,7 @@ public IList<SearchDocument> GetModifiedSearchDocuments(IModule module, DateTime
}
catch (Exception e) // Catch errors here, because of references to Request etc.
{
Exceptions.LogException(new SearchIndexException(dnnModule, e));
Exceptions.LogException(new SearchIndexException(dnnModule, e, nameof(SearchController)));
}

var searchInfoDictionary = new Dictionary<string, List<ISearchItem>>();
Expand Down Expand Up @@ -141,7 +138,7 @@ public IList<SearchDocument> GetModifiedSearchDocuments(IModule module, DateTime
}
catch (Exception e)
{
Exceptions.LogException(new SearchIndexException(dnnModule, e));
Exceptions.LogException(new SearchIndexException(dnnModule, e, nameof(SearchController)));
}

// add it to insights / history. It will only be preserved, if the inner code ran a Log.Preserve = true;
Expand Down
5 changes: 3 additions & 2 deletions Src/Dnn/ToSic.Sxc.Dnn/Dnn/Search/SearchIndexException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace ToSic.Sxc.Search
[InternalApi_DoNotUse_MayChangeWithoutNotice("this is just fyi")]
public class SearchIndexException : Exception
{
public SearchIndexException(ModuleInfo moduleInfo, Exception innerException)
: base("Search: Error while indexing module " + moduleInfo.ModuleID + " on tab " + moduleInfo.TabID + ", portal " + moduleInfo.PortalID, innerException) { }
public SearchIndexException(ModuleInfo module, Exception innerException, string source)
: base(
$"Search: Error in '{source}' while indexing module {module.ModuleID} on tab {module.TabID}, portal {module.PortalID}", innerException) { }
}
}

0 comments on commit cecc33e

Please sign in to comment.