Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dj-nitehawk committed Oct 7, 2023
1 parent 960f469 commit e30b2ab
Show file tree
Hide file tree
Showing 60 changed files with 291 additions and 291 deletions.
2 changes: 1 addition & 1 deletion Benchmark/Benchmarks/BenchBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Benchmark;

public abstract class BenchBase
{
private const string DBName = "mongodb-entities-benchmark";
const string DBName = "mongodb-entities-benchmark";
protected static IMongoCollection<Author> AuthorCollection { get; }
protected static IMongoCollection<Book> BookCollection { get; }
protected static IMongoDatabase Database { get; }
Expand Down
2 changes: 1 addition & 1 deletion Benchmark/Benchmarks/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override Task Official_Driver()
[MemoryDiagnoser]
public class CreateBulk : BenchBase
{
private readonly List<Author> list = new(1000);
readonly List<Author> list = new(1000);

public CreateBulk()
{
Expand Down
6 changes: 3 additions & 3 deletions Benchmark/Benchmarks/FileStorageRead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace Benchmark;
[MemoryDiagnoser]
public partial class FileStorageRead : BenchBase
{
private static readonly MemoryStream memStream = new(new byte[32 * 1024 * 1024]);
static readonly MemoryStream memStream = new(new byte[32 * 1024 * 1024]);

private readonly string fEntityID;
private readonly ObjectId gridFSId;
readonly string fEntityID;
readonly ObjectId gridFSId;

public FileStorageRead()
{
Expand Down
2 changes: 1 addition & 1 deletion Benchmark/Benchmarks/FileStorageWrite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Benchmark;
[MemoryDiagnoser]
public class FileStorageWrite : BenchBase
{
private static readonly MemoryStream memStream = new(new byte[32 * 1024 * 1024]);
static readonly MemoryStream memStream = new(new byte[32 * 1024 * 1024]);

[Benchmark]
public override async Task MongoDB_Entities()
Expand Down
20 changes: 10 additions & 10 deletions Benchmark/Benchmarks/Find.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace Benchmark;
[MemoryDiagnoser]
public class FindOne : BenchBase
{
private readonly List<Author> list = new(1000);
private readonly string guid = Guid.NewGuid().ToString();
readonly List<Author> list = new(1000);
readonly string guid = Guid.NewGuid().ToString();

public FindOne()
{
Expand Down Expand Up @@ -52,8 +52,8 @@ public override async Task Official_Driver()
[MemoryDiagnoser]
public class Find100 : BenchBase
{
private readonly List<Author> list = new(1000);
private readonly string guid = Guid.NewGuid().ToString();
readonly List<Author> list = new(1000);
readonly string guid = Guid.NewGuid().ToString();

public Find100()
{
Expand Down Expand Up @@ -94,8 +94,8 @@ public override async Task Official_Driver()
[MemoryDiagnoser]
public class FindFirst : BenchBase
{
private readonly List<Author> list = new(1000);
private readonly string guid = Guid.NewGuid().ToString();
readonly List<Author> list = new(1000);
readonly string guid = Guid.NewGuid().ToString();

public FindFirst()
{
Expand Down Expand Up @@ -136,8 +136,8 @@ public override async Task Official_Driver()
[MemoryDiagnoser]
public class FindAny : BenchBase
{
private readonly List<Author> list = new(1000);
private readonly string guid = Guid.NewGuid().ToString();
readonly List<Author> list = new(1000);
readonly string guid = Guid.NewGuid().ToString();

public FindAny()
{
Expand Down Expand Up @@ -178,8 +178,8 @@ public override async Task Official_Driver()
[MemoryDiagnoser]
public class FindSingle : BenchBase
{
private readonly List<Author> list = new(1000);
private readonly string guid = Guid.NewGuid().ToString();
readonly List<Author> list = new(1000);
readonly string guid = Guid.NewGuid().ToString();

public FindSingle()
{
Expand Down
4 changes: 2 additions & 2 deletions Benchmark/Benchmarks/Relationships.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace Benchmark;
[MemoryDiagnoser]
public class Relationships : BenchBase
{
private const string bookTitle = "BOOKTITLE";
private const string authorName = "AUTHORNAME";
const string bookTitle = "BOOKTITLE";
const string authorName = "AUTHORNAME";

public Relationships()
{
Expand Down
4 changes: 2 additions & 2 deletions Benchmark/Benchmarks/Save.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Benchmark;
[MemoryDiagnoser]
public class SavePartialVsUpdate : BenchBase
{
private readonly Author author;
readonly Author author;

public SavePartialVsUpdate()
{
Expand Down Expand Up @@ -57,7 +57,7 @@ public override Task Official_Driver()
[MemoryDiagnoser]
public class DBContextVsStaticSave : BenchBase
{
private readonly Author author;
readonly Author author;

public DBContextVsStaticSave()
{
Expand Down
6 changes: 3 additions & 3 deletions Benchmark/Benchmarks/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Benchmark;
[MemoryDiagnoser]
public class UpdateOne : BenchBase
{
private readonly string id = ObjectId.GenerateNewId().ToString();
readonly string id = ObjectId.GenerateNewId().ToString();

public UpdateOne()
{
Expand Down Expand Up @@ -39,8 +39,8 @@ public override Task Official_Driver()
[MemoryDiagnoser]
public class Update100 : BenchBase
{
private readonly List<Author> list = new(1000);
private readonly string guid = Guid.NewGuid().ToString();
readonly List<Author> list = new(1000);
readonly string guid = Guid.NewGuid().ToString();

public Update100()
{
Expand Down
2 changes: 1 addition & 1 deletion Benchmark/Benchmarks/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override async Task Official_Driver()
cts.Dispose();
}

private Task InsertAnEntity()
Task InsertAnEntity()
{
return new Book { Title = "book name" }.SaveAsync();
}
Expand Down
2 changes: 1 addition & 1 deletion Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Benchmark;

public static class Program
{
private static void Main()
static void Main()
{
BenchmarkRunner.Run(typeof(Program).Assembly);
}
Expand Down
12 changes: 6 additions & 6 deletions MongoDB.Entities/Builders/Distinct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ namespace MongoDB.Entities;
/// <typeparam name="TProperty">The type of the property of the entity you'd like to get unique values for</typeparam>
public class Distinct<T, TProperty> where T : IEntity
{
private FieldDefinition<T, TProperty>? field;
private FilterDefinition<T> filter = Builders<T>.Filter.Empty;
private readonly DistinctOptions options = new();
private readonly IClientSessionHandle? session;
private readonly Dictionary<Type, (object filterDef, bool prepend)>? globalFilters;
private bool ignoreGlobalFilters;
FieldDefinition<T, TProperty>? field;
FilterDefinition<T> filter = Builders<T>.Filter.Empty;
readonly DistinctOptions options = new();
readonly IClientSessionHandle? session;
readonly Dictionary<Type, (object filterDef, bool prepend)>? globalFilters;
bool ignoreGlobalFilters;

internal Distinct(IClientSessionHandle? session, Dictionary<Type, (object filterDef, bool prepend)>? globalFilters)
{
Expand Down
14 changes: 7 additions & 7 deletions MongoDB.Entities/Builders/Find.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ internal Find(IClientSessionHandle? session, Dictionary<Type, (object filterDef,
/// <typeparam name="TProjection">The type you'd like to project the results to.</typeparam>
public class Find<T, TProjection> where T : IEntity
{
private FilterDefinition<T> filter = Builders<T>.Filter.Empty;
private readonly List<SortDefinition<T>> sorts = new();
private readonly FindOptions<T, TProjection> options = new();
private readonly IClientSessionHandle? session;
private readonly Dictionary<Type, (object filterDef, bool prepend)>? globalFilters;
private bool ignoreGlobalFilters;
FilterDefinition<T> filter = Builders<T>.Filter.Empty;
readonly List<SortDefinition<T>> sorts = new();
readonly FindOptions<T, TProjection> options = new();
readonly IClientSessionHandle? session;
readonly Dictionary<Type, (object filterDef, bool prepend)>? globalFilters;
bool ignoreGlobalFilters;

internal Find(IClientSessionHandle? session, Dictionary<Type, (object filterDef, bool prepend)>? globalFilters)
{
Expand Down Expand Up @@ -430,7 +430,7 @@ public Task<IAsyncCursor<TProjection>> ExecuteCursorAsync(CancellationToken canc
: DB.Collection<T>().FindAsync(session, mergedFilter, options, cancellation);
}

private void AddTxtScoreToProjection(string propName)
void AddTxtScoreToProjection(string propName)
{
options.Projection ??= "{}";

Expand Down
6 changes: 3 additions & 3 deletions MongoDB.Entities/Builders/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace MongoDB.Entities;
public class Index<T> where T : IEntity
{
internal List<Key<T>> Keys { get; set; } = new List<Key<T>>();
private readonly CreateIndexOptions<T> options = new() { Background = true };
readonly CreateIndexOptions<T> options = new() { Background = true };

/// <summary>
/// Call this method to finalize defining the index after setting the index keys and options.
Expand Down Expand Up @@ -132,13 +132,13 @@ public async Task DropAllAsync(CancellationToken cancellation = default)
await DB.Collection<T>().Indexes.DropAllAsync(cancellation).ConfigureAwait(false);
}

private Task CreateAsync(CreateIndexModel<T> model, CancellationToken cancellation = default)
Task CreateAsync(CreateIndexModel<T> model, CancellationToken cancellation = default)
{
return DB.Collection<T>().Indexes.CreateOneAsync(model, cancellationToken: cancellation);
}
}

internal class Key<T> where T : IEntity
class Key<T> where T : IEntity
{
internal string PropertyName { get; set; }
internal KeyType Type { get; set; }
Expand Down
20 changes: 10 additions & 10 deletions MongoDB.Entities/Builders/PagedSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ internal PagedSearch(IClientSessionHandle? session, Dictionary<Type, (object fil
/// <typeparam name="TProjection">The type you'd like to project the results to.</typeparam>
public class PagedSearch<T, TProjection> where T : IEntity
{
private IAggregateFluent<T>? fluentPipeline;
private FilterDefinition<T> filter = Builders<T>.Filter.Empty;
private readonly List<SortDefinition<T>> sorts = new();
private readonly AggregateOptions options = new();
private PipelineStageDefinition<T, TProjection>? projectionStage;
private readonly IClientSessionHandle? session;
private readonly Dictionary<Type, (object filterDef, bool prepend)>? globalFilters;
private bool ignoreGlobalFilters;
private int pageNumber = 1, pageSize = 100;
IAggregateFluent<T>? fluentPipeline;
FilterDefinition<T> filter = Builders<T>.Filter.Empty;
readonly List<SortDefinition<T>> sorts = new();
readonly AggregateOptions options = new();
PipelineStageDefinition<T, TProjection>? projectionStage;
readonly IClientSessionHandle? session;
readonly Dictionary<Type, (object filterDef, bool prepend)>? globalFilters;
bool ignoreGlobalFilters;
int pageNumber = 1, pageSize = 100;

internal PagedSearch(IClientSessionHandle? session, Dictionary<Type, (object filterDef, bool prepend)>? globalFilters)
{
Expand Down Expand Up @@ -215,7 +215,7 @@ public PagedSearch<T, TProjection> SortByTextScore(Expression<Func<T, object>>?
}
}

private void AddTxtScoreToProjection(string fieldName)
void AddTxtScoreToProjection(string fieldName)
{
if (projectionStage == null)
{
Expand Down
20 changes: 10 additions & 10 deletions MongoDB.Entities/Builders/Replace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ namespace MongoDB.Entities;
/// <typeparam name="T">Any class that implements IEntity</typeparam>
public class Replace<T> where T : IEntity
{
private FilterDefinition<T> filter = Builders<T>.Filter.Empty;
private ReplaceOptions options = new();
private readonly IClientSessionHandle? session;
private readonly List<ReplaceOneModel<T>> models = new();
private readonly ModifiedBy? modifiedBy;
private readonly Dictionary<Type, (object filterDef, bool prepend)>? globalFilters;
private readonly Action<T>? onSaveAction;
private bool ignoreGlobalFilters;
FilterDefinition<T> filter = Builders<T>.Filter.Empty;
ReplaceOptions options = new();
readonly IClientSessionHandle? session;
readonly List<ReplaceOneModel<T>> models = new();
readonly ModifiedBy? modifiedBy;
readonly Dictionary<Type, (object filterDef, bool prepend)>? globalFilters;
readonly Action<T>? onSaveAction;
bool ignoreGlobalFilters;

internal Replace(IClientSessionHandle? session,
ModifiedBy? modifiedBy,
Expand All @@ -36,7 +36,7 @@ internal Replace(IClientSessionHandle? session,
this.onSaveAction = onSaveAction;
}

private T? Entity { get; set; }
T? Entity { get; set; }

/// <summary>
/// Specify an IEntity ID as the matching criteria
Expand Down Expand Up @@ -252,7 +252,7 @@ public async Task<ReplaceOneResult> ExecuteAsync(CancellationToken cancellation
}
}

private void SetModOnAndByValues()
void SetModOnAndByValues()
{
if (Cache<T>.HasModifiedOn && Entity != null) ((IModifiedOn)Entity).ModifiedOn = DateTime.UtcNow;
if (Cache<T>.ModifiedByProp != null && modifiedBy != null)
Expand Down
20 changes: 10 additions & 10 deletions MongoDB.Entities/Builders/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public void AddModification(Template template)
/// <typeparam name="T">Any class that implements IEntity</typeparam>
public class Update<T> : UpdateBase<T> where T : IEntity
{
private readonly List<PipelineStageDefinition<T, T>> stages = new();
private FilterDefinition<T> filter = Builders<T>.Filter.Empty;
private UpdateOptions options = new();
private readonly IClientSessionHandle? session;
private readonly List<UpdateManyModel<T>> models = new();
private readonly Dictionary<Type, (object filterDef, bool prepend)>? globalFilters;
private readonly Action<UpdateBase<T>>? onUpdateAction;
private bool ignoreGlobalFilters;
readonly List<PipelineStageDefinition<T, T>> stages = new();
FilterDefinition<T> filter = Builders<T>.Filter.Empty;
UpdateOptions options = new();
readonly IClientSessionHandle? session;
readonly List<UpdateManyModel<T>> models = new();
readonly Dictionary<Type, (object filterDef, bool prepend)>? globalFilters;
readonly Action<UpdateBase<T>>? onUpdateAction;
bool ignoreGlobalFilters;

internal Update(IClientSessionHandle? session,
Dictionary<Type, (object filterDef, bool prepend)>? globalFilters,
Expand Down Expand Up @@ -451,7 +451,7 @@ public Task<UpdateResult> ExecutePipelineAsync(CancellationToken cancellation =
cancellation);
}

private bool ShouldSetModDate()
bool ShouldSetModDate()
{
//only set mod date by library if user hasn't done anything with the ModifiedOn property

Expand All @@ -463,7 +463,7 @@ private bool ShouldSetModDate()
.Contains($"\"{Cache<T>.ModifiedOnPropName}\""));
}

private Task<UpdateResult> UpdateAsync(FilterDefinition<T> filter, UpdateDefinition<T> definition, UpdateOptions options, IClientSessionHandle? session = null, CancellationToken cancellation = default)
Task<UpdateResult> UpdateAsync(FilterDefinition<T> filter, UpdateDefinition<T> definition, UpdateOptions options, IClientSessionHandle? session = null, CancellationToken cancellation = default)
{
return session == null
? DB.Collection<T>().UpdateManyAsync(filter, definition, options, cancellation)
Expand Down
16 changes: 8 additions & 8 deletions MongoDB.Entities/Builders/UpdateAndGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ internal UpdateAndGet(IClientSessionHandle? session,
/// <typeparam name="TProjection">The type to project to</typeparam>
public class UpdateAndGet<T, TProjection> : UpdateBase<T> where T : IEntity
{
private readonly List<PipelineStageDefinition<T, TProjection>> stages = new();
private FilterDefinition<T> filter = Builders<T>.Filter.Empty;
readonly List<PipelineStageDefinition<T, TProjection>> stages = new();
FilterDefinition<T> filter = Builders<T>.Filter.Empty;
protected private readonly FindOneAndUpdateOptions<T, TProjection> options = new() { ReturnDocument = ReturnDocument.After };
private readonly IClientSessionHandle? session;
private readonly Dictionary<Type, (object filterDef, bool prepend)>? globalFilters;
private readonly Action<UpdateBase<T>>? onUpdateAction;
private bool ignoreGlobalFilters;
readonly IClientSessionHandle? session;
readonly Dictionary<Type, (object filterDef, bool prepend)>? globalFilters;
readonly Action<UpdateBase<T>>? onUpdateAction;
bool ignoreGlobalFilters;

internal UpdateAndGet(IClientSessionHandle? session,
Dictionary<Type, (object filterDef, bool prepend)>? globalFilters,
Expand Down Expand Up @@ -405,7 +405,7 @@ public UpdateAndGet<T, TProjection> IgnoreGlobalFilters()
return await UpdateAndGetAsync(mergedFilter, Builders<T>.Update.Pipeline(stages.ToArray()), options, session, cancellation);
}

private bool ShouldSetModDate()
bool ShouldSetModDate()
{
//only set mod date by library if user hasn't done anything with the ModifiedOn property

Expand All @@ -417,7 +417,7 @@ private bool ShouldSetModDate()
.Contains($"\"{Cache<T>.ModifiedOnPropName}\""));
}

private Task<TProjection> UpdateAndGetAsync(FilterDefinition<T> filter, UpdateDefinition<T> definition, FindOneAndUpdateOptions<T, TProjection> options, IClientSessionHandle? session = null, CancellationToken cancellation = default)
Task<TProjection> UpdateAndGetAsync(FilterDefinition<T> filter, UpdateDefinition<T> definition, FindOneAndUpdateOptions<T, TProjection> options, IClientSessionHandle? session = null, CancellationToken cancellation = default)
{
return session == null
? DB.Collection<T>().FindOneAndUpdateAsync(filter, definition, options, cancellation)
Expand Down
Loading

0 comments on commit e30b2ab

Please sign in to comment.