Skip to content

Commit a70f7e0

Browse files
authoredFeb 8, 2025··
feat: improved perf for HostStrategy (#936)
1 parent e6aeb7c commit a70f7e0

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed
 

‎src/Finbuckle.MultiTenant.AspNetCore/Strategies/HostStrategy.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
namespace Finbuckle.MultiTenant.AspNetCore.Strategies;
1212

13-
public class HostStrategy : IMultiTenantStrategy
13+
public sealed class HostStrategy : IMultiTenantStrategy
1414
{
15-
private readonly string regex;
15+
private readonly Regex regex;
1616

1717
public HostStrategy(string template)
1818
{
@@ -62,7 +62,7 @@ public HostStrategy(string template)
6262
template = template.Replace(Constants.TenantToken, @"(?<identifier>[^\.]+)");
6363
}
6464

65-
this.regex = $"^{template}$";
65+
this.regex = new Regex($"^{template}$", RegexOptions.ExplicitCapture | RegexOptions.Compiled, TimeSpan.FromMilliseconds(100));
6666
}
6767

6868
public Task<string?> GetIdentifierAsync(object context)
@@ -77,9 +77,7 @@ public HostStrategy(string template)
7777

7878
string? identifier = null;
7979

80-
var match = Regex.Match(host.Host, regex,
81-
RegexOptions.ExplicitCapture,
82-
TimeSpan.FromMilliseconds(100));
80+
var match = regex.Match(host.Host);
8381

8482
if (match.Success)
8583
{

0 commit comments

Comments
 (0)
Please sign in to comment.