1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-20 16:07:45 +01:00

optimized grouping counts

This commit is contained in:
Kyle Spearrin 2017-11-24 10:35:43 -05:00
parent 7f102fbb10
commit e1da4ccbd0

View File

@ -69,28 +69,37 @@ angular
$rootScope.vaultCiphers = decCiphers; $rootScope.vaultCiphers = decCiphers;
if ($scope.showGroupingCounts) { if ($scope.showGroupingCounts) {
// compute item count for each grouping var folderCounts = { 'none': 0 };
for (let i = 0; i < decFolders.length; i++) { var collectionCounts = {};
let itemCount = 0;
for (let j = 0; j < decCiphers.length; j++) { decCiphers.forEach((cipher) => {
if (decCiphers[j].folderId === decFolders[i].id) { if (cipher.folderId) {
itemCount++; if (!folderCounts.hasOwnProperty(cipher.folderId)) {
folderCounts[cipher.folderId] = 0;
} }
folderCounts[cipher.folderId]++;
}
else {
folderCounts.none++;
} }
$rootScope.vaultFolders[i].itemCount = itemCount; if (cipher.collectionIds) {
} cipher.collectionIds.forEach((collectionId) => {
for (let i = 0; i < decCollections.length; i++) { if (!collectionCounts.hasOwnProperty(collectionId)) {
let itemCount = 0; collectionCounts[collectionId] = 0;
for (let j = 0; j < decCiphers.length; j++) { }
if (decCiphers[j].collectionIds && collectionCounts[collectionId]++;
decCiphers[j].collectionIds.indexOf(decCollections[i].id) > -1) { });
itemCount++;
}
} }
});
$rootScope.vaultCollections[i].itemCount = itemCount; $rootScope.vaultFolders.forEach((folder) => {
} folder.itemCount = folderCounts[folder.id || 'none'] || 0;
});
$rootScope.vaultCollections.forEach((collection) => {
collection.itemCount = collectionCounts[collection.id] || 0;
});
} }
if (!delayLoad) { if (!delayLoad) {