Skip to content

Commit

Permalink
perf(dashboard): Use storage id for more performant index usage on da…
Browse files Browse the repository at this point in the history
…shboard query

Signed-off-by: Julius Knorr <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Oct 28, 2024
1 parent ef997dc commit fc6b671
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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

0 comments on commit fc6b671

Please sign in to comment.