Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Cache workspace content for propfinds #5948

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Changes from all commits
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
43 changes: 24 additions & 19 deletions lib/DAV/WorkspacePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
use OCA\DAV\Files\FilesHome;
use OCA\Text\AppInfo\Application;
use OCA\Text\Service\WorkspaceService;
use OCP\Files\GenericFileException;
use OCP\Files\IRootFolder;
use OCP\Files\NotPermittedException;
use OCP\Files\StorageNotAvailableException;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\Lock\LockedException;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
use Sabre\DAV\Server;
Expand All @@ -29,23 +33,13 @@ class WorkspacePlugin extends ServerPlugin {
/** @var Server */
private $server;

/** @var WorkspaceService */
private $workspaceService;

/** @var IRootFolder */
private $rootFolder;

/** @var IConfig */
private $config;

/** @var string|null */
private $userId;

public function __construct(WorkspaceService $workspaceService, IRootFolder $rootFolder, IConfig $config, $userId) {
$this->workspaceService = $workspaceService;
$this->rootFolder = $rootFolder;
$this->config = $config;
$this->userId = $userId;
public function __construct(
private WorkspaceService $workspaceService,
private IRootFolder $rootFolder,
private ICacheFactory $cacheFactory,
private IConfig $config,
private ?string $userId
) {
}

/**
Expand Down Expand Up @@ -97,10 +91,21 @@ public function propFind(PropFind $propFind, INode $node) {

// Only return the property for the parent node and ignore it for further in depth nodes
$propFind->handle(self::WORKSPACE_PROPERTY, function () use ($file) {
$cachedContent = '';
if ($file instanceof File) {
return $file->getContent();
$cache = $this->cacheFactory->createDistributed('text_workspace');
$cacheKey = $file->getFileInfo()->getId() . '_' . $file->getFileInfo()->getEtag();
if ($cachedContent = $cache->get($cacheKey)) {
return $cachedContent;
}

try {
$cachedContent = $file->getContent();
$cache->set($cacheKey, $cachedContent, 3600);
} catch (GenericFileException|NotPermittedException|LockedException $e) {
}
Comment on lines +105 to +106
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be logged at least in debug, no?

}
return '';
return $cachedContent;
});
$propFind->handle(self::WORKSPACE_FILE_PROPERTY, function () use ($file) {
if ($file instanceof File) {
Expand Down
Loading