Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public async Task<IDictionary<string, IEnumerable<ThroughputData>>> GetEndpointT

var cutOff = DefaultCutOff();

var data = await dbContext.Throughput.Where(x => queueNames.Contains(x.EndpointName) && x.Date >= cutOff)
var data = await dbContext.Throughput
.AsNoTracking()
.Where(x => queueNames.Contains(x.EndpointName) && x.Date >= cutOff)
.ToListAsync(cancellationToken);

var lookup = data.ToLookup(x => x.EndpointName);
Expand Down Expand Up @@ -170,28 +172,43 @@ public async Task UpdateUserIndicatorOnEndpoints(List<UpdateUserIndicator> userI
using var scope = serviceProvider.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<ServiceControlDbContextBase>();

// Get all relevant sanitized names from endpoints matched by name
var sanitizedNames = await dbContext.Endpoints
.Where(e => updates.Keys.Contains(e.EndpointName) && e.SanitizedEndpointName != null)
.Select(e => e.SanitizedEndpointName)
.Distinct()
.ToListAsync(cancellationToken);

// Get all endpoints that match either by name or sanitized name in a single query
var endpoints = await dbContext.Endpoints
.Where(e => updates.Keys.Contains(e.EndpointName) || (e.SanitizedEndpointName != null && updates.Keys.Contains(e.SanitizedEndpointName)))
.Where(e => updates.Keys.Contains(e.EndpointName)
|| (e.SanitizedEndpointName != null && updates.Keys.Contains(e.SanitizedEndpointName))
|| (e.SanitizedEndpointName != null && sanitizedNames.Contains(e.SanitizedEndpointName)))
.ToListAsync(cancellationToken) ?? [];

foreach (var endpoint in endpoints)
{
if (endpoint.SanitizedEndpointName is not null && updates.TryGetValue(endpoint.SanitizedEndpointName, out var newValueFromSanitizedName))
{
// Direct match by sanitized name
endpoint.UserIndicator = newValueFromSanitizedName;
}
else if (updates.TryGetValue(endpoint.EndpointName, out var newValueFromEndpoint))
{
// Direct match by endpoint name - this should also update all endpoints with the same sanitized name
endpoint.UserIndicator = newValueFromEndpoint;
//update all that match this sanitized name
var sanitizedMatchingEndpoints = await dbContext.Endpoints
.Where(e => e.SanitizedEndpointName == endpoint.SanitizedEndpointName && e.EndpointName != endpoint.EndpointName)
.ToListAsync(cancellationToken) ?? [];
}
else if (endpoint.SanitizedEndpointName != null && sanitizedNames.Contains(endpoint.SanitizedEndpointName))
{
// This endpoint shares a sanitized name with an endpoint that was matched by name
// Find the update value from the endpoint that has this sanitized name
var matchingEndpoint = endpoints.FirstOrDefault(e =>
e.SanitizedEndpointName == endpoint.SanitizedEndpointName &&
updates.ContainsKey(e.EndpointName));

foreach (var matchingEndpointOnSanitizedName in sanitizedMatchingEndpoints)
if (matchingEndpoint != null && updates.TryGetValue(matchingEndpoint.EndpointName, out var cascadedValue))
{
matchingEndpointOnSanitizedName.UserIndicator = newValueFromEndpoint;
_ = dbContext.Endpoints.Update(matchingEndpointOnSanitizedName);
endpoint.UserIndicator = cascadedValue;
}
}
_ = dbContext.Endpoints.Update(endpoint);
Expand Down Expand Up @@ -263,7 +280,9 @@ public async Task<BrokerMetadata> GetBrokerMetadata(CancellationToken cancellati
{
using var scope = serviceProvider.CreateScope();
await using var dbContext = scope.ServiceProvider.GetRequiredService<ServiceControlDbContextBase>();
var existing = await dbContext.LicensingMetadata.SingleOrDefaultAsync(m => m.Key == key, cancellationToken);
var existing = await dbContext.LicensingMetadata
.AsNoTracking()
.SingleOrDefaultAsync(m => m.Key == key, cancellationToken);
if (existing is null)
{
return default;
Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#nullable disable

namespace ServiceControl.Persistence.Sql.MySQL.Migrations
{
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("MySql:CharSet", "utf8mb4");

migrationBuilder.CreateTable(
name: "DailyThroughput",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
EndpointName = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
ThroughputSource = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Date = table.Column<DateOnly>(type: "date", nullable: false),
MessageCount = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_DailyThroughput", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");

migrationBuilder.CreateTable(
name: "LicensingMetadata",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Key = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Data = table.Column<string>(type: "varchar(2000)", maxLength: 2000, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("PK_LicensingMetadata", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");

migrationBuilder.CreateTable(
name: "ThroughputEndpoint",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
EndpointName = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
ThroughputSource = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
SanitizedEndpointName = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
EndpointIndicators = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
UserIndicator = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Scope = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
LastCollectedData = table.Column<DateOnly>(type: "date", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ThroughputEndpoint", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");

migrationBuilder.CreateTable(
name: "TrialLicense",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false, defaultValue: 1),
TrialEndDate = table.Column<DateOnly>(type: "date", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TrialLicense", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");

migrationBuilder.CreateIndex(
name: "UC_DailyThroughput_EndpointName_ThroughputSource_Date",
table: "DailyThroughput",
columns: new[] { "EndpointName", "ThroughputSource", "Date" },
unique: true);

migrationBuilder.CreateIndex(
name: "IX_LicensingMetadata_Key",
table: "LicensingMetadata",
column: "Key",
unique: true);

migrationBuilder.CreateIndex(
name: "UC_ThroughputEndpoint_EndpointName_ThroughputSource",
table: "ThroughputEndpoint",
columns: new[] { "EndpointName", "ThroughputSource" },
unique: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "DailyThroughput");

migrationBuilder.DropTable(
name: "LicensingMetadata");

migrationBuilder.DropTable(
name: "ThroughputEndpoint");

migrationBuilder.DropTable(
name: "TrialLicense");
}
}
}
Loading
Loading