Merge pull request #5211 from sbwalker/dev
fix #5194 - improve performance of retrieving scheduled job logs
This commit is contained in:
commit
c8286148c1
@ -45,7 +45,7 @@
|
||||
<div class="row mb-1 align-items-center">
|
||||
<Label Class="col-sm-3" For="retention" HelpText="Number of log entries to retain for this job" ResourceKey="RetentionLog">Retention Log (Items): </Label>
|
||||
<div class="col-sm-9">
|
||||
<input id="retention" type="number" min="0" step ="1" class="form-control" @bind="@_retentionHistory" maxlength="4" required />
|
||||
<input id="retention" type="number" min="0" step ="1" class="form-control" @bind="@_retentionHistory" maxlength="3" required />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-1 align-items-center">
|
||||
|
@ -44,14 +44,12 @@ else
|
||||
|
||||
private async Task GetJobLogs()
|
||||
{
|
||||
_jobLogs = await JobLogService.GetJobLogsAsync();
|
||||
|
||||
var jobId = -1;
|
||||
if (PageState.QueryString.ContainsKey("id"))
|
||||
{
|
||||
_jobLogs = _jobLogs.Where(item => item.JobId == Int32.Parse(PageState.QueryString["id"])).ToList();
|
||||
jobId = int.Parse(PageState.QueryString["id"]);
|
||||
}
|
||||
|
||||
_jobLogs = _jobLogs.OrderByDescending(item => item.JobLogId).ToList();
|
||||
_jobLogs = await JobLogService.GetJobLogsAsync(jobId);
|
||||
}
|
||||
|
||||
private string DisplayStatus(bool isExecuting, bool? succeeded)
|
||||
|
@ -10,10 +10,11 @@ namespace Oqtane.Services
|
||||
public interface IJobLogService
|
||||
{
|
||||
/// <summary>
|
||||
/// Return a list of all <see cref="JobLog"/> entries
|
||||
/// Return a list of <see cref="JobLog"/> entries
|
||||
/// </summary>
|
||||
/// <param name="jobId"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<JobLog>> GetJobLogsAsync();
|
||||
Task<List<JobLog>> GetJobLogsAsync(int jobId);
|
||||
|
||||
/// <summary>
|
||||
/// Return a <see cref="JobLog"/> entry for the given Id
|
||||
|
@ -15,10 +15,9 @@ namespace Oqtane.Services
|
||||
|
||||
private string Apiurl => CreateApiUrl("JobLog");
|
||||
|
||||
public async Task<List<JobLog>> GetJobLogsAsync()
|
||||
public async Task<List<JobLog>> GetJobLogsAsync(int jobId)
|
||||
{
|
||||
List<JobLog> joblogs = await GetJsonAsync<List<JobLog>>(Apiurl);
|
||||
return joblogs.OrderBy(item => item.StartDate).ToList();
|
||||
return await GetJsonAsync<List<JobLog>>($"{Apiurl}?jobid={jobId}");
|
||||
}
|
||||
|
||||
public async Task<JobLog> GetJobLogAsync(int jobLogId)
|
||||
|
@ -17,12 +17,12 @@ namespace Oqtane.Controllers
|
||||
_jobLogs = jobLogs;
|
||||
}
|
||||
|
||||
// GET: api/<controller>
|
||||
// GET: api/<controller>?jobid=x
|
||||
[HttpGet]
|
||||
[Authorize(Roles = RoleNames.Host)]
|
||||
public IEnumerable<JobLog> Get()
|
||||
public IEnumerable<JobLog> Get(string jobid)
|
||||
{
|
||||
return _jobLogs.GetJobLogs();
|
||||
return _jobLogs.GetJobLogs(int.Parse(jobid));
|
||||
}
|
||||
|
||||
// GET api/<controller>/5
|
||||
|
@ -172,8 +172,7 @@ namespace Oqtane.Infrastructure
|
||||
jobs.UpdateJob(job);
|
||||
|
||||
// trim the job log
|
||||
List<JobLog> logs = jobLogs.GetJobLogs().Where(item => item.JobId == job.JobId)
|
||||
.OrderByDescending(item => item.JobLogId).ToList();
|
||||
List<JobLog> logs = jobLogs.GetJobLogs(job.JobId).ToList();
|
||||
for (int i = logs.Count; i > job.RetentionHistory; i--)
|
||||
{
|
||||
jobLogs.DeleteJobLog(logs[i - 1].JobLogId);
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
@ -6,6 +6,7 @@ namespace Oqtane.Repository
|
||||
public interface IJobLogRepository
|
||||
{
|
||||
IEnumerable<JobLog> GetJobLogs();
|
||||
IEnumerable<JobLog> GetJobLogs(int jobId);
|
||||
JobLog AddJobLog(JobLog jobLog);
|
||||
JobLog UpdateJobLog(JobLog jobLog);
|
||||
JobLog GetJobLog(int jobLogId);
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Models;
|
||||
@ -15,9 +15,17 @@ namespace Oqtane.Repository
|
||||
}
|
||||
|
||||
public IEnumerable<JobLog> GetJobLogs()
|
||||
{
|
||||
return GetJobLogs(-1);
|
||||
}
|
||||
|
||||
public IEnumerable<JobLog> GetJobLogs(int jobId)
|
||||
{
|
||||
return _db.JobLog
|
||||
.AsNoTracking()
|
||||
.Where(item => item.JobId == jobId || jobId == -1)
|
||||
.Include(item => item.Job) // eager load jobs
|
||||
.OrderByDescending(item => item.JobLogId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user