Skip to content

Commit

Permalink
Workaround for possible NRE while indexing ContentItemRecords. (Orcha…
Browse files Browse the repository at this point in the history
  • Loading branch information
Xceno authored and sebastienros committed Jan 18, 2018
1 parent 5753a7c commit 7b971f4
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ public class IndexingTaskExecutor : IIndexingTaskExecutor, IIndexStatisticsProvi
.OrderBy(versionRecord => versionRecord.Id)
.Take(ContentItemsPerLoop)
.ToList()
// In some rare cases a ContentItemRecord without a ContentType can end up in the DB.
// We need to filter out such records, otherwise they will crash the ContentManager.
.Where(x => x.ContentItemRecord != null && x.ContentItemRecord.ContentType != null)
.Select(versionRecord => _contentManager.Get(versionRecord.ContentItemRecord.Id, VersionOptions.VersionRecord(versionRecord.Id)))
.Distinct()
.ToList();
Expand Down Expand Up @@ -220,6 +223,9 @@ public class IndexingTaskExecutor : IIndexingTaskExecutor, IIndexStatisticsProvi
.OrderBy(x => x.Id)
.Take(ContentItemsPerLoop)
.ToList()
// In some rare cases a ContentItemRecord without a ContentType can end up in the DB.
// We need to filter out such records, otherwise they will crash the ContentManager.
.Where(x => x.ContentItemRecord != null && x.ContentItemRecord.ContentType != null)
.GroupBy(x => x.ContentItemRecord.Id)
.Select(group => new { TaskId = group.Max(task => task.Id), Delete = group.Last().Action == IndexingTaskRecord.Delete, Id = group.Key, ContentItem = _contentManager.Get(group.Key, VersionOptions.Latest) })
.OrderBy(x => x.TaskId)
Expand Down

0 comments on commit 7b971f4

Please sign in to comment.