Skip to content

Commit cf4fede

Browse files
committed
Blocking large context collections
1 parent 8f2b2ab commit cf4fede

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

src/Server/Coderr.Server.App/Core/Reports/Jobs/DeleteOldReports.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ OPEN OldReportsCursor
6969
7070
FETCH NEXT FROM OldReportsCursor INTO @ReportId
7171
72-
WHILE @@FETCH_STATUS = 0
72+
-- don't lock jobs because one DB gets filled (cloud service)
73+
WHILE @@FETCH_STATUS = 0 AND @counter < 10000
7374
BEGIN
7475
set @counter = @counter + 1
7576
DELETE FROM ErrorReports WHERE Id = @ReportId

src/Server/Coderr.Server.SqlServer/Coderr.Server.SqlServer.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,4 @@
2525
<ItemGroup>
2626
<EmbeddedResource Include="Schema\*.sql" />
2727
</ItemGroup>
28-
29-
<ItemGroup>
30-
<None Remove="Schema\Coderr.v17.sql" />
31-
</ItemGroup>
3228
</Project>

src/Server/Coderr.Server.SqlServer/ReportAnalyzer/Jobs/Importer.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
using System.Threading.Tasks;
55
using Coderr.Server.Domain.Core.ErrorReports;
66
using Griffin.Data;
7+
using log4net;
78

89
namespace Coderr.Server.SqlServer.ReportAnalyzer.Jobs
910
{
1011
internal class Importer
1112
{
1213
private readonly SqlTransaction _transaction;
1314
private readonly DataTable _dataTable = new DataTable();
15+
private ILog _logger = LogManager.GetLogger(typeof(Importer));
16+
1417

1518
public Importer(SqlTransaction transaction)
1619
{
@@ -26,10 +29,17 @@ public void AddContextCollections(int reportId, ErrorReportContextCollection[] c
2629
{
2730
foreach (var context in contexts)
2831
{
32+
if (context.Properties.Count > 300)
33+
{
34+
_logger.Warn($"Report {reportId}, Ignoring collection {context.Name}, since it got {context.Properties.Count} properties");
35+
continue;
36+
}
37+
2938
foreach (var property in context.Properties)
3039
{
3140
if (property.Value == null)
3241
continue;
42+
3343
var row = CreateDataTableRow(_dataTable, reportId, context, property);
3444
_dataTable.Rows.Add(row);
3545
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
IF EXISTS (SELECT * FROM sys.indexes WHERE name='IDX_ErrorReportCollectionProperties_ReportId'
2+
AND object_id = OBJECT_ID('ErrorReportCollectionProperties'))
3+
begin
4+
CREATE INDEX IDX_ErrorReportCollectionProperties_ReportId
5+
ON ErrorReportCollectionProperties (ReportId);
6+
7+
CREATE INDEX IDX_ErrorReportCollectionInbound_ReportId
8+
ON ErrorReportCollectionInbound (ReportId);
9+
10+
end
11+

0 commit comments

Comments
 (0)