Removing residual files accidentally brought back during merge in Orchard.Indexing

This commit is contained in:
Lombiq
2016-02-10 22:42:53 +01:00
committed by Benedek Farkas
parent d6035f6bb0
commit e823738265
4 changed files with 0 additions and 106 deletions

View File

@@ -1,7 +0,0 @@
namespace Orchard.Indexing.Models {
public class IndexTaskBatchRecord {
public virtual int Id { get; set; }
public virtual int BatchStartIndex { get; set; }
public virtual string ContentType { get; set; }
}
}

View File

@@ -1,25 +0,0 @@
using System.Linq;
using Orchard.Tasks;
using Orchard.Tasks.Indexing;
namespace Orchard.Indexing.Services {
public class CreateUpdateIndexTaskBackgroundTask : IBackgroundTask {
private readonly IIndexTaskBatchManagementService _indexTaskBatchManagementService;
private readonly IIndexingTaskManager _indexingTaskManager;
public CreateUpdateIndexTaskBackgroundTask(IIndexTaskBatchManagementService indexTaskBatchManagementService, IIndexingTaskManager indexingTaskManager) {
_indexTaskBatchManagementService = indexTaskBatchManagementService;
_indexingTaskManager = indexingTaskManager;
}
public void Sweep() {
var contentItemsLists = _indexTaskBatchManagementService.GetNextBatchOfContentItemsToIndex();
foreach (var contentItemsList in contentItemsLists) {
foreach (var contentItem in contentItemsList) {
_indexingTaskManager.CreateUpdateIndexTask(contentItem);
}
}
}
}
}

View File

@@ -1,21 +0,0 @@
using System.Collections.Generic;
using Orchard.ContentManagement;
namespace Orchard.Indexing.Services {
/// <summary>
/// Manages the batches for indexing tasks.
/// </summary>
public interface IIndexTaskBatchManagementService : IDependency {
/// <summary>
/// Registers a content type for the <see cref="CreateUpdateIndexTaskBackgroundTask"/>.
/// </summary>
/// <param name="contentType">The content type.</param>
void RegisterContentType(string contentType);
/// <summary>
/// Returns a list of a list of the registered content items.
/// </summary>
IEnumerable<IEnumerable<ContentItem>> GetNextBatchOfContentItemsToIndex();
}
}

View File

@@ -1,53 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using Orchard.ContentManagement;
using Orchard.Data;
using Orchard.Indexing.Models;
namespace Orchard.Indexing.Services {
public class IndexTaskBatchManagementService : IIndexTaskBatchManagementService {
private readonly IRepository<IndexTaskBatchRecord> _indexTaskBatchRecordRepository;
private readonly IContentManager _contentManager;
private const int BatchSize = 50;
public IndexTaskBatchManagementService(IRepository<IndexTaskBatchRecord> indexTaskBatchRecordRepository, IContentManager contentManager) {
_indexTaskBatchRecordRepository = indexTaskBatchRecordRepository;
_contentManager = contentManager;
}
public void RegisterContentType(string contentType) {
var registeredContentType = _indexTaskBatchRecordRepository.Table.Where(i => i.ContentType == contentType).FirstOrDefault();
if (registeredContentType == null) {
_indexTaskBatchRecordRepository.Create(new IndexTaskBatchRecord { ContentType = contentType, BatchStartIndex = 0 });
}
else {
registeredContentType.BatchStartIndex = 0;
}
}
public IEnumerable<IEnumerable<ContentItem>> GetNextBatchOfContentItemsToIndex() {
var indexTaskBatchRecords = _indexTaskBatchRecordRepository.Table;
if (indexTaskBatchRecords == null) return null;
var contentItemsList = new List<List<ContentItem>>();
foreach (var indexTaskBatchRecord in indexTaskBatchRecords) {
var contentItems = _contentManager.Query(indexTaskBatchRecord.ContentType).Slice(indexTaskBatchRecord.BatchStartIndex, BatchSize).ToList();
if (contentItems.Any()) contentItemsList.Add(contentItems);
if (contentItems.Count == 0 || contentItems.Count < BatchSize) {
_indexTaskBatchRecordRepository.Delete(_indexTaskBatchRecordRepository.Table.FirstOrDefault(i => i.ContentType == indexTaskBatchRecord.ContentType));
}
else {
indexTaskBatchRecord.BatchStartIndex += BatchSize;
}
}
return contentItemsList;
}
}
}