Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update calendar estimation
Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal committed May 30, 2022
commit aaedc95e817c55576ed7413bc2220800bb66ef85
23 changes: 17 additions & 6 deletions apps/dav/lib/UserMigration/CalendarMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
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;

Expand Down Expand Up @@ -211,15 +212,25 @@ private function getUniqueCalendarUri(IUser $user, string $initialCalendarUri):
* {@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);
}

/**
Expand Down