Skip to content
Closed
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
2 changes: 1 addition & 1 deletion apps/systemtags/lib/Search/TagSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
$query->getLimit(),
(int)$query->getCursor(),
$query->getSortOrder() === ISearchQuery::SORT_DATE_DESC ? [
new SearchOrder(ISearchOrder::DIRECTION_DESCENDING, 'mtime'),
new SearchOrder(ISearchOrder::DIRECTION_DESCENDING, 'enforce_mtime'),
] : [],
$user
);
Expand Down
7 changes: 7 additions & 0 deletions lib/private/Files/Cache/SearchBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public function addSearchOrdersToQuery(IQueryBuilder $query, array $orders) {
$field = 'file.fileid';
}

// The mtime hack:
// Mysql really likes to pick an index for sorting if it can't fully satisfy the where
// filter with an index, since search queries pretty much never are fully filtered by index
// mysql often picks an index for sorting instead of the much more useful index for filtering.
Expand All @@ -246,6 +247,12 @@ public function addSearchOrdersToQuery(IQueryBuilder $query, array $orders) {
$field = $query->func()->add($field, $query->createNamedParameter(0));
}

// The index on mtime might be useful for ordering a result set by mtime.
// Use "enforce_mtime" as search order to skip the mtime hack.
if ($field === 'enforce_mtime') {
$field = 'mtime';
}

$query->addOrderBy($field, $order->getDirection());
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/private/Files/Search/SearchOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private function sortFileInfoNoDirection(FileInfo $a, FileInfo $b): int {
case 'mimetype':
return $a->getMimetype() <=> $b->getMimetype();
case 'mtime':
case 'enforce_mtime':
return $a->getMtime() <=> $b->getMtime();
case 'size':
return $a->getSize() <=> $b->getSize();
Expand Down