]> source.dussan.org Git - nextcloud-server.git/commitdiff
Update calendar estimation 32206/head
authorChristopher Ng <chrng8@gmail.com>
Fri, 29 Apr 2022 03:03:01 +0000 (03:03 +0000)
committerChristopher Ng <chrng8@gmail.com>
Mon, 30 May 2022 22:48:15 +0000 (22:48 +0000)
Signed-off-by: Christopher Ng <chrng8@gmail.com>
apps/dav/lib/UserMigration/CalendarMigrator.php

index 5a296a2b5270d541035e4479232b996db27c6522..057f7dce77d81e785425cefd9be51180ab014a66 100644 (file)
@@ -51,6 +51,7 @@ use Sabre\VObject\Property\ICalendar\DateTime;
 use Sabre\VObject\Reader as VObjectReader;
 use Sabre\VObject\UUIDUtil;
 use Safe\Exceptions\StringsException;
+use Symfony\Component\Console\Output\NullOutput;
 use Symfony\Component\Console\Output\OutputInterface;
 use Throwable;
 
@@ -211,15 +212,25 @@ class CalendarMigrator implements IMigrator, ISizeEstimationMigrator {
         * {@inheritDoc}
         */
        public function getEstimatedExportSize(IUser $user): int {
-               $principalUri = $this->getPrincipalUri($user);
+               $calendarExports = $this->getCalendarExports($user, new NullOutput());
+               $calendarCount = count($calendarExports);
+
+               // 150B for top-level properties
+               $size = ($calendarCount * 150) / 1024;
 
-               return array_sum(array_map(
-                       function (ICalendar $calendar) use ($user): int {
-                               // FIXME 1MiB by calendar, no idea if this is accurate and if we should go into more details
-                               return 1000;
+               $componentCount = array_sum(array_map(
+                       function (array $data): int {
+                               /** @var VCalendar $vCalendar */
+                               $vCalendar = $data['vCalendar'];
+                               return count($vCalendar->getComponents());
                        },
-                       $this->calendarManager->getCalendarsForPrincipal($principalUri),
+                       $calendarExports,
                ));
+
+               // 450B for each component (events, todos, alarms, etc.)
+               $size += ($componentCount * 450) / 1024;
+
+               return (int)ceil($size);
        }
 
        /**