Merge pull request #5211 from sbwalker/dev

fix #5194 - improve performance of retrieving scheduled job logs
This commit is contained in:
Shaun Walker 2025-03-31 13:16:52 -04:00 committed by GitHub
commit c8286148c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 24 additions and 18 deletions

View File

@ -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">

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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();
}