aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/UserMigration
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2022-04-29 02:33:45 +0000
committerChristopher Ng <chrng8@gmail.com>2022-05-30 17:49:05 +0000
commit9fbbbc7ca6767ac401d94ee035dd57ae070aae24 (patch)
treedf846dc97c110b35aa186522860748165ff4d282 /apps/dav/lib/UserMigration
parentf2850a6c0634fb7a06896ce1eb501b8105cba0fb (diff)
downloadnextcloud-server-9fbbbc7ca6767ac401d94ee035dd57ae070aae24.tar.gz
nextcloud-server-9fbbbc7ca6767ac401d94ee035dd57ae070aae24.zip
Update contacts estimation
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'apps/dav/lib/UserMigration')
-rw-r--r--apps/dav/lib/UserMigration/ContactsMigrator.php21
1 files changed, 14 insertions, 7 deletions
diff --git a/apps/dav/lib/UserMigration/ContactsMigrator.php b/apps/dav/lib/UserMigration/ContactsMigrator.php
index fc498288810..ae1a61ce4f4 100644
--- a/apps/dav/lib/UserMigration/ContactsMigrator.php
+++ b/apps/dav/lib/UserMigration/ContactsMigrator.php
@@ -48,6 +48,7 @@ use Sabre\VObject\Splitter\VCard as VCardSplitter;
use Sabre\VObject\UUIDUtil;
use Safe\Exceptions\ArrayException;
use Safe\Exceptions\StringsException;
+use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
@@ -198,15 +199,21 @@ class ContactsMigrator implements IMigrator, ISizeEstimationMigrator {
* {@inheritDoc}
*/
public function getEstimatedExportSize(IUser $user): int {
- $principalUri = $this->getPrincipalUri($user);
+ $addressBookExports = $this->getAddressBookExports($user, new NullOutput());
+ $addressBookCount = count($addressBookExports);
- return array_sum(array_map(
- function (array $addressBookInfo) use ($user): int {
- // FIXME 1MiB by addressbook, no idea if this is accurate and if we should go into more details
- return 1000;
- },
- $this->cardDavBackend->getAddressBooksForUser($principalUri),
+ // 50B for each metadata JSON
+ $size = ($addressBookCount * 50) / 1024;
+
+ $contactsCount = array_sum(array_map(
+ fn (array $data): int => count($data['vCards']),
+ $addressBookExports,
));
+
+ // 350B for each contact
+ $size += ($contactsCount * 350) / 1024;
+
+ return (int)ceil($size);
}
/**