Skip to content

Commit

Permalink
perf(boot): Initialize storage wrapper and lock manager more lazy
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Apr 22, 2024
1 parent bba5967 commit 8562d3f
Showing 1 changed file with 10 additions and 55 deletions.
65 changes: 10 additions & 55 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

namespace OCA\FilesLock\AppInfo;

use Closure;
use OC\Files\Filesystem;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\FilesLock\Capability;
Expand All @@ -45,20 +44,13 @@
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Files\Lock\ILockManager;
use OCP\IServerContainer;
use OCP\IUserSession;
use OCP\Server;
use OCP\Util;
use Throwable;

/**
* Class Application
*
* @package OCA\FilesLock\AppInfo
*/
class Application extends App implements IBootstrap {
public const APP_ID = 'files_lock';


public const DAV_PROPERTY_LOCK = '{http://nextcloud.org/ns}lock';
public const DAV_PROPERTY_LOCK_OWNER_TYPE = '{http://nextcloud.org/ns}lock-owner-type';
public const DAV_PROPERTY_LOCK_OWNER = '{http://nextcloud.org/ns}lock-owner';
Expand All @@ -68,30 +60,10 @@ class Application extends App implements IBootstrap {
public const DAV_PROPERTY_LOCK_TIMEOUT = '{http://nextcloud.org/ns}lock-timeout';
public const DAV_PROPERTY_LOCK_TOKEN = '{http://nextcloud.org/ns}lock-token';


/** @var IUserSession */
private $userSession;

/** @var FileService */
private $fileService;

/** @var LockService */
private $lockService;

private ILockManager $lockManager;


/**
* @param array $params
*/
public function __construct(array $params = []) {
parent::__construct(self::APP_ID, $params);
}


/**
* @param IRegistrationContext $context
*/
public function register(IRegistrationContext $context): void {
$context->registerCapability(Capability::class);
$context->registerEventListener(
Expand All @@ -100,46 +72,29 @@ public function register(IRegistrationContext $context): void {
);
}


/**
* @param IBootContext $context
*
* @throws Throwable
*/
public function boot(IBootContext $context): void {
$context->injectFn(Closure::fromCallable([$this, 'registerHooks']));
$this->registerHooks();

$context->injectFn(function (ILockManager $lockManager) use ($context) {
$lockManager->registerLockProvider($context->getAppContainer()->get(LockProvider::class));
$lockManager->registerLazyLockProvider(LockProvider::class);

Check failure on line 79 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedInterfaceMethod

lib/AppInfo/Application.php:79:18: UndefinedInterfaceMethod: Method OCP\Files\Lock\ILockManager::registerLazyLockProvider does not exist (see https://psalm.dev/181)
});
}


/**
* @param IServerContainer $container
*/
public function registerHooks(IServerContainer $container) {
$this->userSession = $container->get(IUserSession::class);
$this->fileService = $container->get(FileService::class);
$this->lockService = $container->get(LockService::class);
$this->lockManager = $container->get(ILockManager::class);

public function registerHooks(): void {
Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper');
}

/**
* @internal
*/
public function addStorageWrapper() {
/** @internal */
public function addStorageWrapper(): void {
Filesystem::addStorageWrapper(
'files_lock', function ($mountPoint, $storage) {
return new LockWrapper(
[
'storage' => $storage,
'lock_manager' => $this->lockManager,
'user_session' => $this->userSession,
'file_service' => $this->fileService,
'lock_service' => $this->lockService
'lock_manager' => Server::get(ILockManager::class),
'user_session' => Server::get(IUserSession::class),
'file_service' => Server::get(FileService::class),
'lock_service' => Server::get(LockService::class)
]
);
}, 10
Expand Down

0 comments on commit 8562d3f

Please sign in to comment.