aboutsummaryrefslogtreecommitdiff
path: root/plugins/VNLib.Plugins.Essentials.Content.Routing
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-08-28 22:00:06 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-08-28 22:00:06 -0400
commit1fe67b21fd3e0fe9e7063cd03e43e1583fce3ce1 (patch)
treeec568fa4b447a0188ced3cc01be61f0ad121ac36 /plugins/VNLib.Plugins.Essentials.Content.Routing
parent204e3a11fa8fcce549a0de2db782f0d0c20b4966 (diff)
Patches & data-store updates
Diffstat (limited to 'plugins/VNLib.Plugins.Essentials.Content.Routing')
-rw-r--r--plugins/VNLib.Plugins.Essentials.Content.Routing/src/IRouteStore.cs3
-rw-r--r--plugins/VNLib.Plugins.Essentials.Content.Routing/src/ManagedRouteStore.cs7
-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
-rw-r--r--plugins/VNLib.Plugins.Essentials.Content.Routing/src/RouteComparer.cs6
-rw-r--r--plugins/VNLib.Plugins.Essentials.Content.Routing/src/Router.cs5
8 files changed, 47 insertions, 38 deletions
diff --git a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/IRouteStore.cs b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/IRouteStore.cs
index 39af773..d7ade6d 100644
--- a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/IRouteStore.cs
+++ b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/IRouteStore.cs
@@ -22,6 +22,7 @@
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
+using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
@@ -36,6 +37,6 @@ namespace VNLib.Plugins.Essentials.Content.Routing
/// </summary>
/// <param name="routes">The collection to store loaded routes to</param>
/// <returns>A task that completes when the routes are added to the collection</returns>
- Task GetAllRoutesAsync(ICollection<Route> routes);
+ Task GetAllRoutesAsync(ICollection<Route> routes, CancellationToken cancellation);
}
}
diff --git a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/ManagedRouteStore.cs b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/ManagedRouteStore.cs
index d859551..e2b87a1 100644
--- a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/ManagedRouteStore.cs
+++ b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/ManagedRouteStore.cs
@@ -22,6 +22,7 @@
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
+using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
@@ -50,13 +51,13 @@ namespace VNLib.Plugins.Essentials.Content.Routing
_routeStore = plugin.GetOrCreateSingleton<DbRouteStore>();
//Ensure the database is created
- _ = plugin.ObserveWork(() => plugin.EnsureDbCreatedAsync<RoutingContext>(plugin), 500);
+ _ = plugin.ObserveWork(() => plugin.EnsureDbCreatedAsync<RoutingContext>(plugin), 1000);
}
}
- public Task GetAllRoutesAsync(ICollection<Route> routes)
+ public Task GetAllRoutesAsync(ICollection<Route> routes, CancellationToken cancellation)
{
- return _routeStore.GetAllRoutesAsync(routes);
+ return _routeStore.GetAllRoutesAsync(routes, cancellation);
}
}
}
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
diff --git a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/RouteComparer.cs b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/RouteComparer.cs
index bd9f3b3..61e8303 100644
--- a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/RouteComparer.cs
+++ b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/RouteComparer.cs
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2022 Vaughn Nugent
+* Copyright (c) 2023 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Plugins.Essentials.Content.Routing
@@ -33,10 +33,10 @@ namespace VNLib.Plugins.Essentials.Content.Routing
/// <summary>
/// Sorts routing rules based on closest match path/hostname routing along with privilage priority
/// </summary>
- internal class RouteComparer : IComparer<Route>
+ internal sealed class RouteComparer : IComparer<Route>
{
//The idea is that hostnames without wildcards are exact, and hostnames with wildcards are "catch all"
- public int Compare(Route x, Route y)
+ public int Compare(Route? x, Route? y)
{
int val = 0;
//If x contains a wildcard in the hostname, then it is less than y
diff --git a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Router.cs b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Router.cs
index 59a88c1..fda572a 100644
--- a/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Router.cs
+++ b/plugins/VNLib.Plugins.Essentials.Content.Routing/src/Router.cs
@@ -25,6 +25,7 @@
using System;
using System.Linq;
using System.Buffers;
+using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections.Concurrent;
@@ -40,7 +41,7 @@ using VNLib.Plugins.Essentials.Content.Routing.Model;
namespace VNLib.Plugins.Essentials.Content.Routing
{
- internal class Router : IPageRouter
+ internal sealed class Router : IPageRouter
{
private static readonly RouteComparer Comparer = new();
@@ -92,7 +93,7 @@ namespace VNLib.Plugins.Essentials.Content.Routing
List<Route> collection = new();
//Load all routes from the backing store and filter them
- await Store.GetAllRoutesAsync(collection);
+ await Store.GetAllRoutesAsync(collection, CancellationToken.None);
Logger.Debug("Found {r} routes in store", collection.Count);