mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Optimization background queries
This commit is contained in:
@@ -57,7 +57,7 @@ namespace Orchard.Core.Settings.Descriptor {
|
||||
|
||||
private ShellDescriptorRecord GetDescriptorRecord() {
|
||||
if (_shellDescriptorRecord == null) {
|
||||
return _shellDescriptorRepository.Table.ToList().SingleOrDefault();
|
||||
return _shellDescriptorRecord = _shellDescriptorRepository.Table.ToList().SingleOrDefault();
|
||||
}
|
||||
|
||||
return _shellDescriptorRecord;
|
||||
@@ -72,11 +72,12 @@ namespace Orchard.Core.Settings.Descriptor {
|
||||
if (shellDescriptorRecord == null) {
|
||||
shellDescriptorRecord = new ShellDescriptorRecord { SerialNumber = 1 };
|
||||
_shellDescriptorRepository.Create(shellDescriptorRecord);
|
||||
_shellDescriptorRecord = shellDescriptorRecord;
|
||||
}
|
||||
else {
|
||||
shellDescriptorRecord.SerialNumber++;
|
||||
}
|
||||
|
||||
_shellDescriptorRecord = shellDescriptorRecord;
|
||||
|
||||
shellDescriptorRecord.Features.Clear();
|
||||
foreach (var feature in enabledFeatures) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Data;
|
||||
@@ -8,45 +9,46 @@ using Orchard.Settings;
|
||||
namespace Orchard.JobsQueue.Services {
|
||||
public class JobsQueueManager : IJobsQueueManager {
|
||||
private readonly IRepository<QueuedJobRecord> _jobRepository;
|
||||
private readonly JobsQueueSettingsPart _jobsQueueSettingsPart;
|
||||
private readonly Lazy<JobsQueueSettingsPart> _jobsQueueSettingsPart;
|
||||
|
||||
public JobsQueueManager(
|
||||
IRepository<QueuedJobRecord> jobRepository,
|
||||
ISiteService siteService) {
|
||||
_jobRepository = jobRepository;
|
||||
_jobsQueueSettingsPart = siteService.GetSiteSettings().As<JobsQueueSettingsPart>();
|
||||
_jobsQueueSettingsPart = new Lazy<JobsQueueSettingsPart>(() => { return siteService.GetSiteSettings().As<JobsQueueSettingsPart>(); });
|
||||
}
|
||||
|
||||
public void Resume() {
|
||||
_jobsQueueSettingsPart.Status = JobsQueueStatus.Idle;
|
||||
_jobsQueueSettingsPart.Value.Status = JobsQueueStatus.Idle;
|
||||
}
|
||||
|
||||
public void Pause() {
|
||||
_jobsQueueSettingsPart.Status = JobsQueueStatus.Paused;
|
||||
_jobsQueueSettingsPart.Value.Status = JobsQueueStatus.Paused;
|
||||
}
|
||||
|
||||
public int GetJobsCount() {
|
||||
return GetMessagesQuery().Count();
|
||||
return _jobRepository
|
||||
.Table
|
||||
.Count();
|
||||
}
|
||||
|
||||
public IEnumerable<QueuedJobRecord> GetJobs(int startIndex, int pageSize) {
|
||||
return GetMessagesQuery()
|
||||
.Skip(startIndex)
|
||||
.Take(pageSize)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public QueuedJobRecord GetJob(int id) {
|
||||
return _jobRepository.Get(id);
|
||||
}
|
||||
|
||||
private IQueryable<QueuedJobRecord> GetMessagesQuery() {
|
||||
var query = _jobRepository
|
||||
IQueryable<QueuedJobRecord> query = _jobRepository
|
||||
.Table
|
||||
.OrderByDescending(x => x.Priority)
|
||||
.ThenByDescending(x => x.CreatedUtc);
|
||||
|
||||
return query;
|
||||
if(startIndex > 0) {
|
||||
query = query.Skip(startIndex);
|
||||
}
|
||||
|
||||
query = query.Take(pageSize);
|
||||
|
||||
return query.ToList();
|
||||
}
|
||||
|
||||
public QueuedJobRecord GetJob(int id) {
|
||||
return _jobRepository.Get(id);
|
||||
}
|
||||
|
||||
public void Delete(QueuedJobRecord job) {
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Orchard.JobsQueue.Services {
|
||||
IEnumerable<QueuedJobRecord> messages;
|
||||
|
||||
while ((messages = _jobsQueueManager.Value.GetJobs(0, 10).ToArray()).Any()) {
|
||||
foreach (var message in messages.AsParallel()) {
|
||||
foreach (var message in messages) {
|
||||
ProcessMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,5 +28,5 @@ namespace Orchard.JobsQueue.Services {
|
||||
|
||||
return queuedJob;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user