-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new features to MongoDbStorage provider (#613)
* New features: * Decimal fields can now be serialized as `NumberDecimal`s instead of raw strings. * Indexes can be automatically created instead of having to manually call the `WithIndexCreation` method. * MiniProfiler sessions can be configured to be automatically expired (deleted) after a certain time period has elapsed. * The `MongoDbStorageOptions` class has been added to allow for setting the above options. * MongoDB C# driver has been updated to the latest version, and obsoleted code elements updated accordingly. * All new features are opt-in; full backwards-compatibility (including binary) is retained. Co-authored-by: Ian Kemp <[email protected]> Co-authored-by: Nick Craver <[email protected]>
- Loading branch information
1 parent
a009d55
commit 39bf8c8
Showing
8 changed files
with
188 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,6 @@ services: | |
- mssql2019 | ||
- mysql | ||
- postgresql | ||
- mongodb | ||
|
||
nuget: | ||
disable_publish_on_pr: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/MiniProfiler.Providers.MongoDB/MongoDbStorageOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
|
||
namespace StackExchange.Profiling | ||
{ | ||
/// <summary> | ||
/// Options for configuring <see cref="MongoDbStorage"/>. | ||
/// </summary> | ||
public class MongoDbStorageOptions | ||
{ | ||
/// <summary> | ||
/// The connection string to use for connecting to MongoDB. | ||
/// Defaults to <c>mongodb://localhost</c>. | ||
/// </summary> | ||
public string? ConnectionString { get; set; } | ||
|
||
/// <summary> | ||
/// Name of the collection in which to store <see cref="MiniProfiler"/> sessions in. | ||
/// Defaults to <c>profilers</c>. | ||
/// </summary> | ||
public string CollectionName { get; set; } = "profilers"; | ||
|
||
/// <summary> | ||
/// If set to <see langword="true"/>, C# <c>decimal</c> fields will be serialized as <c>NumberDecimal</c>s in MongoDB. | ||
/// If set to <see langword="false"/>, will serialize these fields as strings (backwards-compatible with older versions of this provider). | ||
/// Defaults to <see langword="true"/>. | ||
/// </summary> | ||
public bool SerializeDecimalFieldsAsNumberDecimal { get; set; } = true; | ||
|
||
/// <summary> | ||
/// Specifies whether relevant indexes will automatically created when this provider is instantiated. | ||
/// Defaults to <see langword="true" />. | ||
/// </summary> | ||
public bool AutomaticallyCreateIndexes { get; set; } = true; | ||
|
||
/// <summary> | ||
/// Specifies whether relevant indexes will automatically recreated if creation fails (e.g. because something with | ||
/// different options was previously created). | ||
/// *THIS DROPS EXISTING DATA* | ||
/// Defaults to <see langword="false" />. | ||
/// </summary> | ||
public bool AutomaticallyRecreateIndexes { get; set; } = false; | ||
|
||
/// <summary> | ||
/// Gets or sets how long to cache each <see cref="MiniProfiler"/> for, in absolute terms. | ||
/// Defaults to one hour. | ||
/// </summary> | ||
/// <remarks><list type="bullet"> | ||
/// <item>You need to either set <see cref="AutomaticallyCreateIndexes"/> to true or call | ||
/// <see cref="MongoDbStorage.WithIndexCreation(TimeSpan)"/> for this value to have any effect.</item> | ||
/// <item>Setting this option will drop any (<see cref="MiniProfiler.Started"/>, ascending) index previously | ||
/// defined, including those with custom options.</item> | ||
/// </list></remarks> | ||
public TimeSpan CacheDuration { get; set; } = TimeSpan.FromHours(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters