Skip to content

Commit

Permalink
Cache migrators separately
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Jun 3, 2022
1 parent 28e1cae commit 14b7f2a
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/Service/UserMigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,25 @@ public function __construct(
* @return int Estimated size in KiB
*/
private function estimateExportSize(IUser $user, ?array $filteredMigratorList = null): int {
$cacheKey = $user->getUID();
if ($filteredMigratorList !== null) {
$cacheKey .= '::' . json_encode($filteredMigratorList);
}

if ($this->internalCache->hasKey($cacheKey)) {
return $this->internalCache->get($cacheKey);
}

// 1MiB for base user data
$size = 1024;

foreach ($this->getMigrators() as $migrator) {
if ($filteredMigratorList !== null && !in_array($migrator->getId(), $filteredMigratorList)) {
continue;
}
$cacheKey = $user->getUID() . '::' . $migrator->getId();
if ($this->internalCache->hasKey($cacheKey)) {
$size += $this->internalCache->get($cacheKey);
continue;
}
if ($migrator instanceof ISizeEstimationMigrator) {
$size += $migrator->getEstimatedExportSize($user);
$migratorSize = $migrator->getEstimatedExportSize($user);
$this->internalCache->set($cacheKey, $migratorSize);
$size += $migratorSize;
}
}

$this->internalCache->set($cacheKey, $size);
return $size;
}

Expand Down

0 comments on commit 14b7f2a

Please sign in to comment.