]> source.dussan.org Git - nextcloud-server.git/commitdiff
Update contacts estimation
authorChristopher Ng <chrng8@gmail.com>
Fri, 29 Apr 2022 02:33:45 +0000 (02:33 +0000)
committerChristopher Ng <chrng8@gmail.com>
Mon, 30 May 2022 17:49:05 +0000 (17:49 +0000)
Signed-off-by: Christopher Ng <chrng8@gmail.com>
apps/dav/lib/UserMigration/ContactsMigrator.php

index fc49828881099806576714b84690673e4179ddb2..ae1a61ce4f400881c6b531eba6231a804e9593bb 100644 (file)
@@ -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);
        }
 
        /**