Skip to content

Commit

Permalink
chore: Refactor after review
Browse files Browse the repository at this point in the history
  • Loading branch information
unchase committed Sep 4, 2021
1 parent 93e7691 commit 6669e92
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 92 deletions.
28 changes: 20 additions & 8 deletions src/MiniProfiler.Providers.MySql/MySqlStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Dapper;
using MySqlConnector;
Expand Down Expand Up @@ -227,14 +228,14 @@ public override async Task<MiniProfiler> LoadAsync(Guid id)
}

/// <summary>
/// Sets a particular profiler session so it is considered "unviewed"
/// Sets a particular profiler session so it is considered "unviewed"
/// </summary>
/// <param name="user">The user to set this profiler ID as unviewed for.</param>
/// <param name="id">The profiler ID to set unviewed.</param>
public override void SetUnviewed(string user, Guid id) => ToggleViewed(user, id, false);

/// <summary>
/// Asynchronously sets a particular profiler session so it is considered "unviewed"
/// Asynchronously sets a particular profiler session so it is considered "unviewed"
/// </summary>
/// <param name="user">The user to set this profiler ID as unviewed for.</param>
/// <param name="id">The profiler ID to set unviewed.</param>
Expand Down Expand Up @@ -374,6 +375,17 @@ SELECT Id
/// </summary>
protected override DbConnection GetConnection() => new MySqlConnection(ConnectionString);

/// <summary>
/// SQL statements to create the SQL Server CE schema names.
/// </summary>
protected override IEnumerable<string> GetSchemaNameCreationScripts(IEnumerable<string> schemaNames)
{
foreach (var schemaName in schemaNames)
{
yield return $@"CREATE SCHEMA IF NOT EXISTS [{schemaName}]";
}
}

/// <summary>
/// SQL statements to create the MySQL tables.
/// </summary>
Expand All @@ -393,8 +405,8 @@ User varchar(100) null,
MachineName varchar(100) null,
CustomLinksJson longtext,
ClientTimingsRedirectCount int null,
UNIQUE INDEX IX_{MiniProfilersTable}_Id (Id), -- displaying results selects everything based on the main MiniProfilers.Id column
INDEX IX_{MiniProfilersTable}_User_HasUserViewed (User, HasUserViewed) -- speeds up a query that is called on every .Stop()
UNIQUE INDEX IX_{Regex.Replace(MiniProfilersTable, IndexNameWrongSymbolsReplacePattern, "_")}_Id (Id), -- displaying results selects everything based on the main MiniProfilers.Id column
INDEX IX_{Regex.Replace(MiniProfilersTable, IndexNameWrongSymbolsReplacePattern, "_")}_User_HasUserViewed (User, HasUserViewed) -- speeds up a query that is called on every .Stop()
) engine=InnoDB collate utf8mb4_bin;";
yield return $@"
CREATE TABLE {MiniProfilerTimingsTable}
Expand All @@ -409,8 +421,8 @@ StartMilliseconds decimal(15,3) not null,
IsRoot bool not null,
Depth smallint not null,
CustomTimingsJson longtext null,
UNIQUE INDEX IX_{MiniProfilerTimingsTable}_Id (Id),
INDEX IX_{MiniProfilerTimingsTable}_MiniProfilerId (MiniProfilerId)
UNIQUE INDEX IX_{Regex.Replace(MiniProfilerTimingsTable, IndexNameWrongSymbolsReplacePattern, "_")}_Id (Id),
INDEX IX_{Regex.Replace(MiniProfilerTimingsTable, IndexNameWrongSymbolsReplacePattern, "_")}_MiniProfilerId (MiniProfilerId)
) engine=InnoDB collate utf8mb4_bin;";
yield return $@"
CREATE TABLE {MiniProfilerClientTimingsTable}
Expand All @@ -421,8 +433,8 @@ MiniProfilerId char(36) not null collate ascii_general_ci,
Name varchar(200) not null,
Start decimal(9, 3) not null,
Duration decimal(9, 3) not null,
UNIQUE INDEX IX_{MiniProfilerClientTimingsTable}_Id (Id),
INDEX IX_{MiniProfilerClientTimingsTable}_MiniProfilerId (MiniProfilerId)
UNIQUE INDEX IX_{Regex.Replace(MiniProfilerClientTimingsTable, IndexNameWrongSymbolsReplacePattern, "_")}_Id (Id),
INDEX IX_{Regex.Replace(MiniProfilerClientTimingsTable, IndexNameWrongSymbolsReplacePattern, "_")}_MiniProfilerId (MiniProfilerId)
) engine=InnoDB collate utf8mb4_bin;";
}

Expand Down
30 changes: 21 additions & 9 deletions src/MiniProfiler.Providers.PostgreSql/PostgreSqlStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace StackExchange.Profiling.Storage
Expand Down Expand Up @@ -242,14 +243,14 @@ public override async Task<MiniProfiler> LoadAsync(Guid id)
}

/// <summary>
/// Sets a particular profiler session so it is considered "unviewed"
/// Sets a particular profiler session so it is considered "unviewed"
/// </summary>
/// <param name="user">The user to set this profiler ID as unviewed for.</param>
/// <param name="id">The profiler ID to set unviewed.</param>
public override void SetUnviewed(string user, Guid id) => ToggleViewed(user, id, false);

/// <summary>
/// Asynchronously sets a particular profiler session so it is considered "unviewed"
/// Asynchronously sets a particular profiler session so it is considered "unviewed"
/// </summary>
/// <param name="user">The user to set this profiler ID as unviewed for.</param>
/// <param name="id">The profiler ID to set unviewed.</param>
Expand Down Expand Up @@ -390,6 +391,17 @@ Select Id
/// </summary>
protected override DbConnection GetConnection() => new NpgsqlConnection(ConnectionString);

/// <summary>
/// SQL statements to create the SQL Server CE schema names.
/// </summary>
protected override IEnumerable<string> GetSchemaNameCreationScripts(IEnumerable<string> schemaNames)
{
foreach (var schemaName in schemaNames)
{
yield return $@"CREATE SCHEMA IF NOT EXISTS [{schemaName}]";
}
}

/// <summary>
/// SQL statements to create the SQL Server tables.
/// </summary>
Expand All @@ -411,10 +423,10 @@ MachineName varchar(100) null,
ClientTimingsRedirectCount integer null
);
-- displaying results selects everything based on the main MiniProfilers.Id column
CREATE UNIQUE INDEX IX_{MiniProfilersTable}_Id ON {MiniProfilersTable} (Id);
CREATE UNIQUE INDEX IX_{Regex.Replace(MiniProfilersTable, IndexNameWrongSymbolsReplacePattern, "_")}_Id ON {MiniProfilersTable} (Id);
-- speeds up a query that is called on every .Stop()
CREATE INDEX IX_{MiniProfilersTable}_User_HasUserViewed_Includes ON {MiniProfilersTable} (""User"", HasUserViewed);
CREATE INDEX IX_{Regex.Replace(MiniProfilersTable, IndexNameWrongSymbolsReplacePattern, "_")}_User_HasUserViewed_Includes ON {MiniProfilersTable} (""User"", HasUserViewed);
CREATE TABLE {MiniProfilerTimingsTable}
(
Expand All @@ -430,8 +442,8 @@ StartMilliseconds decimal(15,3) not null,
CustomTimingsJson varchar null
);
CREATE UNIQUE INDEX IX_{MiniProfilerTimingsTable}_Id ON {MiniProfilerTimingsTable} (Id);
CREATE INDEX IX_{MiniProfilerTimingsTable}_MiniProfilerId ON {MiniProfilerTimingsTable} (MiniProfilerId);
CREATE UNIQUE INDEX IX_{Regex.Replace(MiniProfilerTimingsTable, IndexNameWrongSymbolsReplacePattern, "_")}_Id ON {MiniProfilerTimingsTable} (Id);
CREATE INDEX IX_{Regex.Replace(MiniProfilerTimingsTable, IndexNameWrongSymbolsReplacePattern, "_")}_MiniProfilerId ON {MiniProfilerTimingsTable} (MiniProfilerId);
CREATE TABLE {MiniProfilerClientTimingsTable}
(
Expand All @@ -443,8 +455,8 @@ Start decimal(9, 3) not null,
Duration decimal(9, 3) not null
);
CREATE UNIQUE INDEX IX_{MiniProfilerClientTimingsTable}_Id on {MiniProfilerClientTimingsTable} (Id);
CREATE INDEX IX_{MiniProfilerClientTimingsTable}_MiniProfilerId on {MiniProfilerClientTimingsTable} (MiniProfilerId);
CREATE UNIQUE INDEX IX_{Regex.Replace(MiniProfilerClientTimingsTable, IndexNameWrongSymbolsReplacePattern, "_")}_Id on {MiniProfilerClientTimingsTable} (Id);
CREATE INDEX IX_{Regex.Replace(MiniProfilerClientTimingsTable, IndexNameWrongSymbolsReplacePattern, "_")}_MiniProfilerId on {MiniProfilerClientTimingsTable} (MiniProfilerId);
";
}
}
Expand Down
Loading

0 comments on commit 6669e92

Please sign in to comment.