Skip to content

Commit

Permalink
improve query behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticroentgen committed Jul 30, 2024
1 parent b738927 commit d11a3c0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ApiController : Controller
public async Task<IResult> GetRunners()
{
var db = new ActionsRunnerContext();
var recentRunners = await db.Runners.Include(x => x.Lifecycle).OrderByDescending(x => x.RunnerId).Take(100).ToListAsync();
var recentRunners = await db.Runners.Include(x => x.Lifecycle).Include(x => x.Job).OrderByDescending(x => x.RunnerId).Take(100).ToListAsync();
return Results.Json(recentRunners);
}

Expand Down
5 changes: 5 additions & 0 deletions Database/DbContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

namespace GithubActionsOrchestrator.Database;
using Microsoft.EntityFrameworkCore;
Expand All @@ -12,6 +13,8 @@ public class ActionsRunnerContext()
public DbSet<Job> Jobs { get; set; }
public DbSet<RunnerLifecycle> RunnerLifecycles { get; set; }



protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseNpgsql(Program.Config.DbConnectionString);

Expand Down Expand Up @@ -148,6 +151,8 @@ public class Job

//Relations
public int? RunnerId { get; set; }

[JsonIgnore]
public Runner Runner { get; set; }
public bool Orphan { get; set; }
public string RequestedProfile { get; set; }
Expand Down
5 changes: 4 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ public static void Main(string[] args)
.AllowAnyHeader(); // Allow all headers
});
});
builder.Services.AddControllers();
builder.Services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
});

builder.Services.AddSingleton(svc =>
{
Expand Down

0 comments on commit d11a3c0

Please sign in to comment.