Remove unnecessary call to fetch a collection when it's known that there is none

This commit is contained in:
Vishnu Mohandas 2020-10-11 05:53:28 +05:30
parent 8f8594f07f
commit 6f2f95b038

View file

@ -111,29 +111,24 @@ class CollectionsService {
if (_localCollections.containsKey(path)) {
return _localCollections[path];
}
var collection = await getFolder(path);
if (collection.id == null) {
final key = CryptoUtil.generateKey();
final encryptedKeyData = CryptoUtil.encryptSync(key, _config.getKey());
final encryptedPath =
CryptoUtil.encryptSync(utf8.encode(path), _config.getKey());
collection = await createCollection(Collection(
null,
null,
Sodium.bin2base64(encryptedKeyData.encryptedData),
Sodium.bin2base64(encryptedKeyData.nonce),
path,
CollectionType.folder,
Sodium.bin2base64(encryptedPath.encryptedData),
Sodium.bin2base64(encryptedPath.nonce),
null,
null,
));
_localCollections[path] = collection;
return collection;
} else {
return collection;
}
final key = CryptoUtil.generateKey();
final encryptedKeyData = CryptoUtil.encryptSync(key, _config.getKey());
final encryptedPath =
CryptoUtil.encryptSync(utf8.encode(path), _config.getKey());
final collection = await createCollection(Collection(
null,
null,
Sodium.bin2base64(encryptedKeyData.encryptedData),
Sodium.bin2base64(encryptedKeyData.nonce),
path,
CollectionType.folder,
Sodium.bin2base64(encryptedPath.encryptedData),
Sodium.bin2base64(encryptedPath.nonce),
null,
null,
));
_localCollections[path] = collection;
return collection;
}
Future<Collection> createCollection(Collection collection) async {