-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #714 from Blazam-App/v1-Dev
Memory Optimizations
- Loading branch information
Showing
28 changed files
with
217 additions
and
83 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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Microsoft.Extensions.ObjectPool; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.Contracts; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BLAZAM.Common.Data | ||
{ | ||
public static class ApplicationStatistics | ||
{ | ||
public static int ADContextCount { get; private set; } | ||
public static void AddADContext() | ||
{ | ||
ADContextCount++; | ||
} | ||
public static void RemoveADContext() | ||
{ | ||
if (ADContextCount > 0) | ||
ADContextCount--; | ||
|
||
} | ||
|
||
|
||
public static int DBContextCount { get; private set; } | ||
public static void AddDBContext() | ||
{ | ||
DBContextCount++; | ||
} | ||
public static void RemoveDBContext() | ||
{ | ||
if (DBContextCount > 0) | ||
DBContextCount--; | ||
|
||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using BLAZAM.Common.Data.Database; | ||
using BLAZAM.Database.Exceptions; | ||
|
||
namespace BLAZAM.Database.Context | ||
{ | ||
/// <summary> | ||
/// The primary database factory for BLAZAM. | ||
/// Creates <see cref="IDatabaseContext"/> types | ||
/// that can have a number of database type backings | ||
/// </summary> | ||
public interface IUserDatabaseFactory : IAppDatabaseFactory | ||
{ | ||
} | ||
} |
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,52 @@ | ||
using BLAZAM.Common.Data.Database; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.Entity.Core.Mapping; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BLAZAM.Database.Context | ||
{ | ||
public class UserDatabaseFactory : IUserDatabaseFactory, IDisposable | ||
{ | ||
private readonly IAppDatabaseFactory _appDatabaseFactory; | ||
|
||
public UserDatabaseFactory(IAppDatabaseFactory appDatabaseFactory) | ||
{ | ||
_appDatabaseFactory = appDatabaseFactory; | ||
} | ||
|
||
public DatabaseType DatabaseType => _appDatabaseFactory.DatabaseType; | ||
|
||
public bool ApplyDatabaseMigrations(bool force = false) => _appDatabaseFactory.ApplyDatabaseMigrations(force); | ||
|
||
public Task<bool> ApplyDatabaseMigrationsAsync(bool force = false) => _appDatabaseFactory.ApplyDatabaseMigrationsAsync(force); | ||
|
||
private List<IDatabaseContext> _userContexts = new(); | ||
|
||
public IDatabaseContext CreateDbContext() | ||
{ | ||
var ctx= _appDatabaseFactory.CreateDbContext(); | ||
_userContexts.Add(ctx); | ||
|
||
return ctx; | ||
} | ||
|
||
public async Task<IDatabaseContext> CreateDbContextAsync() | ||
{ | ||
var ctx = await _appDatabaseFactory.CreateDbContextAsync(); | ||
_userContexts.Add(ctx); | ||
|
||
return ctx; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
foreach(var ctx in _userContexts) | ||
{ | ||
ctx.Dispose(); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.