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(dashboard): Use storage id for more performant index usage on dashboard query #1556

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion lib/Service/RecentPagesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
Expand All @@ -30,6 +31,7 @@ public function __construct(
protected IMimeTypeLoader $mimeTypeLoader,
protected IURLGenerator $urlGenerator,
protected IL10N $l10n,
protected IRootFolder $rootFolder,
) {
}

Expand All @@ -50,6 +52,7 @@ public function forUser(IUser $user, int $limit = 10): array {

$qb = $this->dbc->getQueryBuilder();
$appData = $this->getAppDataFolderName();
$storageId = $this->rootFolder->get($appData)->getStorage()->getCache()->getNumericStorageId();
$mimeTypeMd = $this->mimeTypeLoader->getId('text/markdown');

$expressions = [];
Expand All @@ -64,7 +67,8 @@ public function forUser(IUser $user, int $limit = 10): array {
$qb->select('p.*', 'f.mtime as timestamp', 'f.name as filename', 'f.path as path')
->from('filecache', 'f')
->leftJoin('f', 'collectives_pages', 'p', $qb->expr()->eq('f.fileid', 'p.file_id'))
->where($qb->expr()->orX(...$expressions))
->where($qb->expr()->eq('f.storage', $qb->createNamedParameter($storageId, IQueryBuilder::PARAM_STR)))
->andWhere($qb->expr()->orX(...$expressions))
->andWhere($qb->expr()->eq('f.mimetype', $qb->createNamedParameter($mimeTypeMd, IQueryBuilder::PARAM_INT)))
->orderBy('f.mtime', 'DESC')
->setMaxResults($limit);
Expand Down
6 changes: 5 additions & 1 deletion tests/Unit/Service/RecentPagesServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCA\Collectives\Service\NotFoundException;
use OCA\Collectives\Service\RecentPagesService;
use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
Expand All @@ -32,14 +33,17 @@ protected function setUp(): void {
$mimeTypeLoader = $this->createMock(IMimeTypeLoader::class);
$urlGenerator = $this->createMock(IURLGenerator::class);
$l10n = $this->createMock(IL10N::class);
$rootFolder = $this->createMock(IRootFolder::class);

$this->service = new RecentPagesService(
$this->collectiveService,
$dbc,
$config,
$mimeTypeLoader,
$urlGenerator,
$l10n);
$l10n,
$rootFolder
);

$this->user = $this->createMock(IUser::class);
$this->user->method('getUID')->willReturn('user');
Expand Down
Loading