Skip to content

Commit

Permalink
Merge pull request #17800 from umbraco/v13/bugfix/corrupt-examine-das…
Browse files Browse the repository at this point in the history
…hboard

Make sure Examine dashboard still functions when an index is corrupt
  • Loading branch information
bergmania authored Dec 12, 2024
2 parents 129d369 + 0f9a8bd commit f95fb78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/Umbraco.Infrastructure/Examine/ExamineIndexRebuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ private void RebuildIndexes(bool onlyEmptyIndexes, TimeSpan delay, CancellationT
{
// If an index exists but it has zero docs we'll consider it empty and rebuild
IIndex[] indexes = (onlyEmptyIndexes
? _examineManager.Indexes.Where(x =>
!x.IndexExists() || (x is IIndexStats stats && stats.GetDocumentCount() == 0))
? _examineManager.Indexes.Where(ShouldRebuild)
: _examineManager.Indexes).ToArray();

if (indexes.Length == 0)
Expand Down Expand Up @@ -228,4 +227,17 @@ private void RebuildIndexes(bool onlyEmptyIndexes, TimeSpan delay, CancellationT
}
}
}

private bool ShouldRebuild(IIndex index)
{
try
{
return !index.IndexExists() || (index is IIndexStats stats && stats.GetDocumentCount() == 0);
}
catch (Exception e)
{
_logger.LogError(e, "An error occured trying to get determine index shouldRebuild status for index {IndexName}. The index will NOT be considered for rebuilding", index.Name);
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private ExamineIndexModel CreateModel(IIndex index)
documentCount = indexDiag.GetDocumentCount();
fieldCount = indexDiag.GetFieldNames().Count();
}
catch (FileNotFoundException ex)
catch (Exception ex)
{
// Safe catch that will allow to rebuild a corrupted index
documentCount = 0;
Expand Down

0 comments on commit f95fb78

Please sign in to comment.