- AssetRepository: all Skip() formulas changed from (page-1)*size to page*size - JobRecordRepository: same formula change for GetPastRootJobs - AssetController: removed Page+1 bridge conversion, passes Page directly - JobsController: GetPast default changed from 1 to 0, added validation - AlbumController, TagController, PersonController: consistent Page<0/PageSize<1 validation - IAssetRepository XML doc: 1-based → zero-based - Home.razor: shifted all internal page state from 1-based to 0-based Closes #95
79 lines
2.3 KiB
C#
79 lines
2.3 KiB
C#
using Butter.Types;
|
|
using Lactose.Context;
|
|
using Lactose.Models;
|
|
|
|
namespace Lactose.Repositories;
|
|
|
|
/// <inheritdoc />
|
|
public class JobRecordRepository(LactoseDbContext context) : IJobRecordRepository {
|
|
/// <inheritdoc />
|
|
public void Insert(JobRecord job) {
|
|
job.ModifiedAt = DateTime.UtcNow;
|
|
context.JobRecords.Add(job);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void Update(JobRecord job) {
|
|
job.ModifiedAt = DateTime.UtcNow;
|
|
context.JobRecords.Update(job);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public List<JobRecord> GetAll() =>
|
|
context.JobRecords
|
|
.OrderByDescending(j => j.Finished ?? j.Created)
|
|
.ToList();
|
|
|
|
static readonly EJobStatus[] PastStatuses = [EJobStatus.Completed, EJobStatus.CompletedWithErrors, EJobStatus.Failed, EJobStatus.Canceled];
|
|
|
|
/// <inheritdoc />
|
|
public List<JobRecord> GetPastRootJobs(int page, int pageSize, out int total) {
|
|
var query = context.JobRecords
|
|
.Where(j => j.ParentJobId == null && PastStatuses.Contains(j.Status));
|
|
|
|
total = query.Count();
|
|
|
|
return query
|
|
.OrderByDescending(j => j.Finished ?? j.Created)
|
|
.Skip(page * pageSize)
|
|
.Take(pageSize)
|
|
.ToList();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public List<JobRecord> GetChildren(Guid parentId) =>
|
|
context.JobRecords
|
|
.Where(j => j.ParentJobId == parentId)
|
|
.OrderBy(j => j.Created)
|
|
.ToList();
|
|
|
|
/// <inheritdoc />
|
|
public List<JobRecord> GetChildrenModifiedSince(Guid parentId, DateTime since) =>
|
|
context.JobRecords
|
|
.Where(j => j.ParentJobId == parentId && j.ModifiedAt != null && j.ModifiedAt > since)
|
|
.OrderBy(j => j.Created)
|
|
.ToList();
|
|
|
|
/// <inheritdoc />
|
|
public JobRecord? GetById(Guid id) =>
|
|
context.JobRecords.Find(id);
|
|
|
|
/// <inheritdoc />
|
|
public int DeleteOldJobs(DateTime cutoff) {
|
|
var old = context.JobRecords
|
|
.Where(j => j.Finished != null && j.Finished < cutoff)
|
|
.ToList();
|
|
var count = old.Count;
|
|
if (count > 0) {
|
|
context.JobRecords.RemoveRange(old);
|
|
}
|
|
return count;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void Save() => context.SaveChanges();
|
|
|
|
/// <inheritdoc />
|
|
public void Dispose() => context.Dispose();
|
|
}
|