mirror of
https://github.com/bitwarden/server.git
synced 2025-07-16 15:17:33 -05:00
Removed caching
This commit is contained in:
@ -1,7 +0,0 @@
|
||||
namespace Bit.Core
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public const string UserIdCacheKey = "User:Id_{0}";
|
||||
}
|
||||
}
|
@ -7,23 +7,18 @@ using DataTableProxy;
|
||||
using Bit.Core.Domains;
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
using StackExchange.Redis.Extensions.Core;
|
||||
|
||||
namespace Bit.Core.Repositories.SqlServer
|
||||
{
|
||||
public class CipherRepository : Repository<Cipher, Guid>, ICipherRepository
|
||||
{
|
||||
private readonly ICacheClient _cacheClient;
|
||||
|
||||
public CipherRepository(GlobalSettings globalSettings, ICacheClient cacheClient)
|
||||
: this(globalSettings.SqlServer.ConnectionString, cacheClient)
|
||||
public CipherRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.SqlServer.ConnectionString)
|
||||
{ }
|
||||
|
||||
public CipherRepository(string connectionString, ICacheClient cacheClient)
|
||||
public CipherRepository(string connectionString)
|
||||
: base(connectionString)
|
||||
{
|
||||
_cacheClient = cacheClient;
|
||||
}
|
||||
{ }
|
||||
|
||||
public async Task<Cipher> GetByIdAsync(Guid id, Guid userId)
|
||||
{
|
||||
@ -87,11 +82,11 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateUserEmailPasswordAndCiphersAsync(User user, IEnumerable<Cipher> ciphers)
|
||||
public Task UpdateUserEmailPasswordAndCiphersAsync(User user, IEnumerable<Cipher> ciphers)
|
||||
{
|
||||
if(ciphers.Count() == 0)
|
||||
{
|
||||
return;
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
using(var connection = new SqlConnection(ConnectionString))
|
||||
@ -176,8 +171,7 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup user cache
|
||||
await _cacheClient.RemoveAllAsync(new string[] { string.Format(Constants.UserIdCacheKey, user.Id) });
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task CreateAsync(IEnumerable<Cipher> ciphers)
|
||||
|
@ -5,37 +5,22 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Domains;
|
||||
using Dapper;
|
||||
using StackExchange.Redis.Extensions.Core;
|
||||
|
||||
namespace Bit.Core.Repositories.SqlServer
|
||||
{
|
||||
public class UserRepository : Repository<User, Guid>, IUserRepository
|
||||
{
|
||||
private readonly ICacheClient _cacheClient;
|
||||
|
||||
public UserRepository(GlobalSettings globalSettings, ICacheClient cacheClient)
|
||||
: this(globalSettings.SqlServer.ConnectionString, cacheClient)
|
||||
public UserRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.SqlServer.ConnectionString)
|
||||
{ }
|
||||
|
||||
public UserRepository(string connectionString, ICacheClient cacheClient)
|
||||
public UserRepository(string connectionString)
|
||||
: base(connectionString)
|
||||
{
|
||||
_cacheClient = cacheClient;
|
||||
}
|
||||
{ }
|
||||
|
||||
public override async Task<User> GetByIdAsync(Guid id)
|
||||
{
|
||||
var cacheKey = string.Format(Constants.UserIdCacheKey, id);
|
||||
|
||||
var user = await _cacheClient.GetAsync<User>(cacheKey);
|
||||
if(user != null)
|
||||
{
|
||||
return user;
|
||||
}
|
||||
|
||||
user = await base.GetByIdAsync(id);
|
||||
await _cacheClient.AddAsync(cacheKey, user);
|
||||
return user;
|
||||
return await base.GetByIdAsync(id);
|
||||
}
|
||||
|
||||
public async Task<User> GetByEmailAsync(string email)
|
||||
@ -54,18 +39,11 @@ namespace Bit.Core.Repositories.SqlServer
|
||||
public override async Task ReplaceAsync(User user)
|
||||
{
|
||||
await base.ReplaceAsync(user);
|
||||
await PurgeCacheAsync(user);
|
||||
}
|
||||
|
||||
public override async Task DeleteAsync(User user)
|
||||
{
|
||||
await base.DeleteAsync(user);
|
||||
await PurgeCacheAsync(user);
|
||||
}
|
||||
|
||||
private async Task PurgeCacheAsync(User user)
|
||||
{
|
||||
await _cacheClient.RemoveAllAsync(new string[] { string.Format(Constants.UserIdCacheKey, user.Id) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@
|
||||
"DataTableProxy": "1.2.0",
|
||||
"Sendgrid": "6.3.4",
|
||||
"StackExchange.Redis": "1.0.488",
|
||||
"StackExchange.Redis.Extensions.Newtonsoft": "1.3.5",
|
||||
"PushSharp": "4.0.10"
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user