aboutsummaryrefslogtreecommitdiff
path: root/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model')
-rw-r--r--plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/DbRouteStore.cs52
-rw-r--r--plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs2
-rw-r--r--plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/RoutingContext.cs6
-rw-r--r--plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/XmlRouteStore.cs4
4 files changed, 35 insertions, 29 deletions
diff --git a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/DbRouteStore.cs b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/DbRouteStore.cs
index 0c2fca6..b90ee65 100644
--- a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/DbRouteStore.cs
+++ b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/DbRouteStore.cs
@@ -24,6 +24,7 @@
using System;
using System.Linq;
+using System.Threading;
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -31,13 +32,17 @@ using Microsoft.EntityFrameworkCore;
using VNLib.Plugins.Extensions.Data;
using VNLib.Plugins.Extensions.Loading.Sql;
+using VNLib.Plugins.Extensions.Data.Abstractions;
+using VNLib.Plugins.Extensions.Data.Extensions;
namespace VNLib.Plugins.Essentials.Content.Routing.Model
{
- internal class DbRouteStore : DbStore<Route>, IRouteStore
+ internal sealed class DbRouteStore : DbStore<Route>, IRouteStore
{
private readonly DbContextOptions Options;
+ public override IDbQueryLookup<Route> QueryTable { get; } = new DbQueries();
+
public DbRouteStore(PluginBase plugin)
{
//Load the db context options
@@ -45,41 +50,42 @@ namespace VNLib.Plugins.Essentials.Content.Routing.Model
}
///<inheritdoc/>
- public Task GetAllRoutesAsync(ICollection<Route> routes)
+ public Task GetAllRoutesAsync(ICollection<Route> routes, CancellationToken cancellation)
{
//Get all routes as a single page from the database
- return GetPageAsync(routes, 0, int.MaxValue);
+ return this.GetPageAsync(routes, 0, int.MaxValue, cancellation);
}
///<inheritdoc/>
- public override string RecordIdBuilder => Guid.NewGuid().ToString("N");
+ public override string GetNewRecordId() => Guid.NewGuid().ToString("N");
///<inheritdoc/>
- protected override IQueryable<Route> GetCollectionQueryBuilder(TransactionalDbContext context, params string[] constraints)
- {
- string hostname = constraints[0];
- return from route in context.Set<Route>()
- where route.Hostname == hostname
- select route;
- }
+ public override IDbContextHandle GetNewContext() => new RoutingContext(Options);
///<inheritdoc/>
- protected override IQueryable<Route> GetSingleQueryBuilder(TransactionalDbContext context, params string[] constraints)
+ public override void OnRecordUpdate(Route newRecord, Route currentRecord)
{
- string id = constraints[0];
- return from route in context.Set<Route>()
- where route.Id == id
- select route;
+ throw new NotSupportedException();
}
- ///<inheritdoc/>
- public override TransactionalDbContext NewContext() => new RoutingContext(Options);
-
- ///<inheritdoc/>
- protected override void OnRecordUpdate(Route newRecord, Route currentRecord)
+ private sealed record class DbQueries : IDbQueryLookup<Route>
{
- throw new NotSupportedException();
- }
+ public IQueryable<Route> GetCollectionQueryBuilder(IDbContextHandle context, params string[] constraints)
+ {
+ string hostname = constraints[0];
+ return from route in context.Set<Route>()
+ where route.Hostname == hostname
+ select route;
+ }
+ public IQueryable<Route> GetSingleQueryBuilder(IDbContextHandle context, params string[] constraints)
+ {
+
+ string id = constraints[0];
+ return from route in context.Set<Route>()
+ where route.Id == id
+ select route;
+ }
+ }
}
}
diff --git a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs
index 789d72f..ebd92ad 100644
--- a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs
+++ b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/Route.cs
@@ -33,7 +33,7 @@ using VNLib.Plugins.Extensions.Data;
namespace VNLib.Plugins.Essentials.Content.Routing.Model
{
[Index(nameof(Id), IsUnique = true)]
- internal class Route : DbModelBase
+ internal sealed class Route : DbModelBase
{
public const FpRoutine RewriteRoutine = (FpRoutine)50;
diff --git a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/RoutingContext.cs b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/RoutingContext.cs
index 185b2f2..1a8d82a 100644
--- a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/RoutingContext.cs
+++ b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/RoutingContext.cs
@@ -31,7 +31,7 @@ using VNLib.Plugins.Extensions.Loading.Sql;
namespace VNLib.Plugins.Essentials.Content.Routing.Model
{
- internal class RoutingContext : TransactionalDbContext, IDbTableDefinition
+ internal sealed class RoutingContext : TransactionalDbContext, IDbTableDefinition
{
public DbSet<Route> Routes { get; set; }
@@ -41,8 +41,8 @@ namespace VNLib.Plugins.Essentials.Content.Routing.Model
{
}
- public RoutingContext()
- {}
+ public RoutingContext():base()
+ { }
#nullable enable
diff --git a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/XmlRouteStore.cs b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/XmlRouteStore.cs
index 2dcc25c..fce193e 100644
--- a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/XmlRouteStore.cs
+++ b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Model/XmlRouteStore.cs
@@ -57,7 +57,7 @@ namespace VNLib.Plugins.Essentials.Content.Routing.Model
}
///<inheritdoc/>
- public async Task GetAllRoutesAsync(ICollection<Route> routes)
+ public async Task GetAllRoutesAsync(ICollection<Route> routes, CancellationToken cancellation)
{
using VnMemoryStream memStream = new();
@@ -65,7 +65,7 @@ namespace VNLib.Plugins.Essentials.Content.Routing.Model
await using (FileStream routeFile = new(_routeFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
//Read the route file into memory
- await routeFile.CopyToAsync(memStream, 4096, MemoryUtil.Shared, CancellationToken.None);
+ await routeFile.CopyToAsync(memStream, 8192, MemoryUtil.Shared, cancellation);
}
//Rewind the memory stream