1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-04 01:22:50 -05:00

refactor cipher queries by user. tuned indexing.

This commit is contained in:
Kyle Spearrin
2018-04-24 12:48:43 -04:00
parent ac4f789782
commit 165ee97d2f
16 changed files with 321 additions and 175 deletions

View File

@ -12,7 +12,6 @@ using Bit.Api.Utilities;
using Bit.Core.Utilities;
using Core.Models.Data;
using System.Collections.Generic;
using Microsoft.AspNetCore.Identity;
using Bit.Core.Models.Table;
namespace Bit.Api.Controllers
@ -87,22 +86,13 @@ namespace Bit.Api.Controllers
}
[HttpGet("")]
public async Task<ListResponseModel<CipherDetailsResponseModel>> Get([FromQuery]Core.Enums.CipherType? type = null)
public async Task<ListResponseModel<CipherDetailsResponseModel>> Get()
{
var userId = _userService.GetProperUserId(User).Value;
IEnumerable<CipherDetails> ciphers;
if(type.HasValue)
{
ciphers = await _cipherRepository.GetManyByTypeAndUserIdAsync(type.Value, userId);
}
else
{
ciphers = await _cipherRepository.GetManyByUserIdAsync(userId);
}
var hasOrgs = _currentContext.Organizations.Any();
var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId, hasOrgs);
Dictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict = null;
if(_currentContext.Organizations.Any())
if(hasOrgs)
{
var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdAsync(userId);
collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);
@ -184,24 +174,6 @@ namespace Bit.Api.Controllers
return response;
}
[Obsolete]
[HttpGet("details")]
public async Task<ListResponseModel<CipherDetailsResponseModel>> GetCollections()
{
var userId = _userService.GetProperUserId(User).Value;
var ciphers = await _cipherRepository.GetManyByUserIdHasCollectionsAsync(userId);
Dictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict = null;
if(_currentContext.Organizations.Any())
{
var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdAsync(userId);
collectionCiphersGroupDict = collectionCiphers.GroupBy(c => c.CipherId).ToDictionary(s => s.Key);
}
var responses = ciphers.Select(c => new CipherDetailsResponseModel(c, _globalSettings, collectionCiphersGroupDict));
return new ListResponseModel<CipherDetailsResponseModel>(responses);
}
[HttpGet("organization-details")]
public async Task<ListResponseModel<CipherMiniDetailsResponseModel>> GetOrganizationCollections(string organizationId)
{

View File

@ -55,12 +55,13 @@ namespace Bit.Api.Controllers
var organizationUserDetails = await _organizationUserRepository.GetManyDetailsByUserAsync(user.Id,
OrganizationUserStatusType.Confirmed);
var hasEnabledOrgs = organizationUserDetails.Any(o => o.Enabled);
var folders = await _folderRepository.GetManyByUserIdAsync(user.Id);
var ciphers = await _cipherRepository.GetManyByUserIdAsync(user.Id);
var ciphers = await _cipherRepository.GetManyByUserIdAsync(user.Id, hasEnabledOrgs);
IEnumerable<Collection> collections = null;
IDictionary<Guid, IGrouping<Guid, CollectionCipher>> collectionCiphersGroupDict = null;
if(organizationUserDetails.Any(o => o.Enabled))
if(hasEnabledOrgs)
{
collections = await _collectionRepository.GetManyByUserIdAsync(user.Id, false);
var collectionCiphers = await _collectionCipherRepository.GetManyByUserIdAsync(user.Id);