perf(search): prefix-by-default Deployments and config-audit search; bounded Contains opt-in (ScadaBridge#50)
Deployments free-text search and the config-audit EntityName filter no longer emit LIKE '%term%' by default. Prefix (LIKE 'term%') is the default; substring is an explicit opt-in (DeploymentSearchMode.Contains / entityNameContains) always bounded by a DeployedAt/Timestamp window (explicit, else 30 days). Migration PrefixSearchIndexes adds DeployedBy, RevisionHash and EntityName indexes. Deployments page gains a 'Match anywhere' checkbox. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
+20
-10
@@ -57,7 +57,7 @@ public class DeploymentManagerRepository : IDeploymentManagerRepository
|
||||
/// status-count aggregation needs every status of the otherwise-identical set.
|
||||
/// </param>
|
||||
/// <returns>The composed, unordered, untracked query.</returns>
|
||||
private IQueryable<DeploymentInstanceJoin> BuildListQuery(DeploymentListFilter filter, bool applyStatus)
|
||||
internal IQueryable<DeploymentInstanceJoin> BuildListQuery(DeploymentListFilter filter, bool applyStatus)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(filter);
|
||||
|
||||
@@ -93,16 +93,26 @@ public class DeploymentManagerRepository : IDeploymentManagerRepository
|
||||
query = query.Where(r => scope.Contains(r.SiteId));
|
||||
}
|
||||
|
||||
if (filter.EffectiveDeployedFrom(DateTimeOffset.UtcNow) is { } from)
|
||||
query = query.Where(r => r.DeployedAt >= from);
|
||||
|
||||
if (filter.NormalizedSearch is { } search)
|
||||
{
|
||||
// Substring match across the four identifiers a deployment is findable
|
||||
// by. Translated to LIKE '%term%' by both providers; case-insensitivity
|
||||
// is the database collation's (SQL Server default CI, SQLite ASCII LIKE).
|
||||
query = query.Where(r =>
|
||||
r.InstanceUniqueName.Contains(search)
|
||||
|| r.DeploymentId.Contains(search)
|
||||
|| r.DeployedBy.Contains(search)
|
||||
|| (r.RevisionHash != null && r.RevisionHash.Contains(search)));
|
||||
// Default: PREFIX match across the four identifiers a deployment is findable
|
||||
// by (LIKE 'term%', index-seekable; case-insensitivity is the database
|
||||
// collation's). Contains is the explicit opt-in scan (LIKE '%term%') and is
|
||||
// always bounded by the DeployedAt window applied above (ScadaBridge#50).
|
||||
query = filter.SearchMode == DeploymentSearchMode.Contains
|
||||
? query.Where(r =>
|
||||
r.InstanceUniqueName.Contains(search)
|
||||
|| r.DeploymentId.Contains(search)
|
||||
|| r.DeployedBy.Contains(search)
|
||||
|| (r.RevisionHash != null && r.RevisionHash.Contains(search)))
|
||||
: query.Where(r =>
|
||||
r.InstanceUniqueName.StartsWith(search)
|
||||
|| r.DeploymentId.StartsWith(search)
|
||||
|| r.DeployedBy.StartsWith(search)
|
||||
|| (r.RevisionHash != null && r.RevisionHash.StartsWith(search)));
|
||||
}
|
||||
|
||||
return query;
|
||||
@@ -873,7 +883,7 @@ public class DeploymentManagerRepository : IDeploymentManagerRepository
|
||||
/// lockstep. Not a public contract — <see cref="DeploymentListRow"/> is what
|
||||
/// leaves this class.
|
||||
/// </summary>
|
||||
private sealed class DeploymentInstanceJoin
|
||||
internal sealed class DeploymentInstanceJoin
|
||||
{
|
||||
/// <summary>Deployment record primary key.</summary>
|
||||
public int Id { get; init; }
|
||||
|
||||
Reference in New Issue
Block a user