mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-19 17:51:45 +08:00
Fixes errors during Indexing (#8349)
This commit is contained in:
@@ -45,7 +45,7 @@ namespace Orchard.Indexing.Handlers {
|
||||
var fieldStorage = _fieldStorageProvider.BindStorage(localPart, localField);
|
||||
var indexName = infosetPart.TypeDefinition.Name.ToLower() + "-" + field.Name.ToLower();
|
||||
|
||||
var membersContext = new DescribeMembersContext(fieldStorage, values => {
|
||||
var membersContext = new DescribeMembersContext(null, fieldStorage, values => {
|
||||
|
||||
foreach (var value in values) {
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace Orchard.Indexing.Handlers {
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}, localField);
|
||||
|
||||
foreach (var driver in drivers) {
|
||||
driver.Describe(membersContext);
|
||||
|
||||
@@ -20,8 +20,7 @@ namespace Orchard.Indexing.Services {
|
||||
/// This class is synchronized using a lock file as both command line and web workers can potentially use it,
|
||||
/// and singleton locks would not be shared accross those two.
|
||||
/// </remarks>
|
||||
public class IndexingTaskExecutor : IIndexingTaskExecutor, IIndexStatisticsProvider
|
||||
{
|
||||
public class IndexingTaskExecutor : IIndexingTaskExecutor, IIndexStatisticsProvider {
|
||||
private readonly IRepository<IndexingTaskRecord> _taskRepository;
|
||||
private readonly IRepository<ContentItemVersionRecord> _contentRepository;
|
||||
private IIndexProvider _indexProvider;
|
||||
@@ -160,13 +159,22 @@ namespace Orchard.Indexing.Services {
|
||||
.OrderBy(versionRecord => versionRecord.Id)
|
||||
.Take(ContentItemsPerLoop)
|
||||
.ToList()
|
||||
.Select(versionRecord => {
|
||||
try {
|
||||
// In some rare cases a ContentItemVersionRecord without a ContentItemRecord can end up in the DB.
|
||||
// in that case ContentManager throws a ObjectNotFoundException.
|
||||
// e.g. NHibernate.ObjectNotFoundException: No row with the given identifier exists[Orchard.ContentManagement.Records.ContentItemRecord#148]
|
||||
return _contentManager.Get(versionRecord.ContentItemRecord.Id, VersionOptions.VersionRecord(versionRecord.Id));
|
||||
}
|
||||
catch {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
// 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)))
|
||||
.Where(content => content != null && content.ContentType != null)
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
// if no more elements to index, switch to update mode
|
||||
if (contentItems.Count == 0) {
|
||||
indexSettings.Mode = IndexingMode.Update;
|
||||
@@ -288,7 +296,7 @@ namespace Orchard.Indexing.Services {
|
||||
}
|
||||
|
||||
} while (loop);
|
||||
}
|
||||
}
|
||||
|
||||
// save current state of the index
|
||||
indexSettings.LastIndexedUtc = _clock.UtcNow;
|
||||
@@ -328,12 +336,10 @@ namespace Orchard.Indexing.Services {
|
||||
/// <summary>
|
||||
/// Loads the settings file or create a new default one if it doesn't exist
|
||||
/// </summary>
|
||||
public IndexSettings LoadSettings(string indexName)
|
||||
{
|
||||
public IndexSettings LoadSettings(string indexName) {
|
||||
var indexSettings = new IndexSettings();
|
||||
var settingsFilename = GetSettingsFileName(indexName);
|
||||
if (_appDataFolder.FileExists(settingsFilename))
|
||||
{
|
||||
if (_appDataFolder.FileExists(settingsFilename)) {
|
||||
var content = _appDataFolder.ReadFile(settingsFilename);
|
||||
indexSettings = IndexSettings.Parse(content);
|
||||
}
|
||||
@@ -372,7 +378,7 @@ namespace Orchard.Indexing.Services {
|
||||
if (contentItem == null ||
|
||||
contentItem.TypeDefinition == null ||
|
||||
contentItem.TypeDefinition.Settings == null) {
|
||||
return new TypeIndexing {Indexes = ""};
|
||||
return new TypeIndexing { Indexes = "" };
|
||||
}
|
||||
return contentItem.TypeDefinition.Settings.GetModel<TypeIndexing>();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Orchard.ContentManagement.FieldStorage;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.ContentManagement.Handlers {
|
||||
@@ -8,18 +9,25 @@ namespace Orchard.ContentManagement.Handlers {
|
||||
private readonly Action<string, Type, LocalizedString, LocalizedString> _processMember;
|
||||
private readonly IFieldStorage _storage;
|
||||
private readonly Action<IEnumerable> _apply;
|
||||
private readonly ContentPartFieldDefinition _contentPartFieldDefinition;
|
||||
|
||||
public DescribeMembersContext(Action<string, Type, LocalizedString, LocalizedString> processMember) : this(processMember, null, null) {
|
||||
public DescribeMembersContext(Action<string, Type, LocalizedString, LocalizedString> processMember)
|
||||
: this(processMember, null, null, null) {
|
||||
}
|
||||
|
||||
public DescribeMembersContext(IFieldStorage storage, Action<IEnumerable> apply)
|
||||
: this(null, storage, apply) {
|
||||
: this(null, storage, apply, null) {
|
||||
}
|
||||
|
||||
public DescribeMembersContext(Action<string, Type, LocalizedString, LocalizedString> processMember, IFieldStorage storage, Action<IEnumerable> apply) {
|
||||
public DescribeMembersContext(Action<string, Type, LocalizedString, LocalizedString> processMember, IFieldStorage storage, Action<IEnumerable> apply)
|
||||
: this(null, storage, apply, null) {
|
||||
}
|
||||
|
||||
public DescribeMembersContext(Action<string, Type, LocalizedString, LocalizedString> processMember, IFieldStorage storage, Action<IEnumerable> apply, ContentPartFieldDefinition contentPartFieldDefinition) {
|
||||
_processMember = processMember;
|
||||
_storage = storage;
|
||||
_apply = apply;
|
||||
_contentPartFieldDefinition = contentPartFieldDefinition;
|
||||
}
|
||||
|
||||
public DescribeMembersContext Member(string storageName, Type storageType) {
|
||||
@@ -43,6 +51,9 @@ namespace Orchard.ContentManagement.Handlers {
|
||||
var f = enumerate();
|
||||
var field = Activator.CreateInstance<TField>();
|
||||
field.Storage = _storage;
|
||||
if (field.PartFieldDefinition == null) {
|
||||
field.PartFieldDefinition = _contentPartFieldDefinition;
|
||||
}
|
||||
_apply(f(field));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user