mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
feat(recent-search): pass recent_limit config value to getRecentSearch function
feat(recent-search): pass recent_limit config value to getRecentSearch function Signed-off-by: Cristian Scheid <cristianscheid@gmail.com> Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
This commit is contained in:
parent
8bd68b5a3a
commit
0a52332a48
13 changed files with 44 additions and 7 deletions
|
|
@ -17,7 +17,7 @@ class Capabilities implements ICapability {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return array{dav: array{chunking: string, search_supports_creation_time: bool, search_supports_upload_time: bool, bulkupload?: string, absence-supported?: bool, absence-replacement?: bool}}
|
||||
* @return array{dav: array{chunking: string, search_supports_creation_time: bool, search_supports_upload_time: bool, search_supports_last_activity: bool, bulkupload?: string, absence-supported?: bool, absence-replacement?: bool}}
|
||||
*/
|
||||
public function getCapabilities() {
|
||||
$capabilities = [
|
||||
|
|
@ -25,6 +25,7 @@ class Capabilities implements ICapability {
|
|||
'chunking' => '1.0',
|
||||
'search_supports_creation_time' => true,
|
||||
'search_supports_upload_time' => true,
|
||||
'search_supports_last_activity' => true,
|
||||
]
|
||||
];
|
||||
if ($this->config->getSystemValueBool('bulkupload.enabled', true)) {
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ class FilesPlugin extends ServerPlugin {
|
|||
public const METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag';
|
||||
public const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time';
|
||||
public const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time';
|
||||
public const LAST_ACTIVITY_PROPERTYNAME = '{http://nextcloud.org/ns}last_activity';
|
||||
public const SHARE_NOTE = '{http://nextcloud.org/ns}note';
|
||||
public const SHARE_HIDE_DOWNLOAD_PROPERTYNAME = '{http://nextcloud.org/ns}hide-download';
|
||||
public const SUBFOLDER_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-folder-count';
|
||||
|
|
@ -443,6 +444,10 @@ class FilesPlugin extends ServerPlugin {
|
|||
return $node->getFileInfo()->getCreationTime();
|
||||
});
|
||||
|
||||
$propFind->handle(self::LAST_ACTIVITY_PROPERTYNAME, function () use ($node) {
|
||||
return $node->getFileInfo()->getLastActivity();
|
||||
});
|
||||
|
||||
foreach ($node->getFileInfo()->getMetadata() as $metadataKey => $metadataValue) {
|
||||
$propFind->handle(self::FILE_METADATA_PREFIX . $metadataKey, $metadataValue);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ class FileSearchBackend implements ISearchBackend {
|
|||
new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
|
||||
new SearchPropertyDefinition('{DAV:}creationdate', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
|
||||
new SearchPropertyDefinition('{http://nextcloud.org/ns}upload_time', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
|
||||
new SearchPropertyDefinition('{http://nextcloud.org/ns}last_activity', true, false, true, SearchPropertyDefinition::DATATYPE_DATETIME),
|
||||
new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||
new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN),
|
||||
new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, true, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||
|
|
@ -303,6 +304,8 @@ class FileSearchBackend implements ISearchBackend {
|
|||
return $node->getNode()->getCreationTime();
|
||||
case '{http://nextcloud.org/ns}upload_time':
|
||||
return $node->getNode()->getUploadTime();
|
||||
case '{http://nextcloud.org/ns}last_activity':
|
||||
return $node->getNode()->getLastActivity();
|
||||
case FilesPlugin::SIZE_PROPERTYNAME:
|
||||
return $node->getSize();
|
||||
case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME:
|
||||
|
|
@ -331,6 +334,8 @@ class FileSearchBackend implements ISearchBackend {
|
|||
$direction = $order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING;
|
||||
if (str_starts_with($order->property->name, FilesPlugin::FILE_METADATA_PREFIX)) {
|
||||
return new SearchOrder($direction, substr($order->property->name, strlen(FilesPlugin::FILE_METADATA_PREFIX)), IMetadataQuery::EXTRA);
|
||||
} elseif ($order->property->name === FilesPlugin::LAST_ACTIVITY_PROPERTYNAME) {
|
||||
return new SearchOrder($direction, 'last_activity');
|
||||
} else {
|
||||
return new SearchOrder($direction, $this->mapPropertyNameToColumn($order->property));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@
|
|||
"required": [
|
||||
"chunking",
|
||||
"search_supports_creation_time",
|
||||
"search_supports_upload_time"
|
||||
"search_supports_upload_time",
|
||||
"search_supports_last_activity"
|
||||
],
|
||||
"properties": {
|
||||
"chunking": {
|
||||
|
|
@ -43,6 +44,9 @@
|
|||
"search_supports_upload_time": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"search_supports_last_activity": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"bulkupload": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ class CapabilitiesTest extends TestCase {
|
|||
'chunking' => '1.0',
|
||||
'search_supports_creation_time' => true,
|
||||
'search_supports_upload_time' => true,
|
||||
'search_supports_last_activity' => true,
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $capabilities->getCapabilities());
|
||||
|
|
@ -51,6 +52,7 @@ class CapabilitiesTest extends TestCase {
|
|||
'chunking' => '1.0',
|
||||
'search_supports_creation_time' => true,
|
||||
'search_supports_upload_time' => true,
|
||||
'search_supports_last_activity' => true,
|
||||
'bulkupload' => '1.0',
|
||||
],
|
||||
];
|
||||
|
|
@ -73,6 +75,7 @@ class CapabilitiesTest extends TestCase {
|
|||
'chunking' => '1.0',
|
||||
'search_supports_creation_time' => true,
|
||||
'search_supports_upload_time' => true,
|
||||
'search_supports_last_activity' => true,
|
||||
'absence-supported' => true,
|
||||
'absence-replacement' => true,
|
||||
],
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ use OCP\AppFramework\Http\ContentSecurityPolicy;
|
|||
use OCP\AppFramework\Http\RedirectResponse;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Services\IAppConfig;
|
||||
use OCP\AppFramework\Services\IInitialState;
|
||||
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
|
|
@ -60,6 +61,7 @@ class ViewController extends Controller {
|
|||
private UserConfig $userConfig,
|
||||
private ViewConfig $viewConfig,
|
||||
private FilenameValidator $filenameValidator,
|
||||
private IAppConfig $appConfig,
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
}
|
||||
|
|
@ -171,6 +173,7 @@ class ViewController extends Controller {
|
|||
$this->initialState->provideInitialState('storageStats', $storageInfo);
|
||||
$this->initialState->provideInitialState('config', $this->userConfig->getConfigs());
|
||||
$this->initialState->provideInitialState('viewConfigs', $this->viewConfig->getConfigs());
|
||||
$this->initialState->provideInitialState('recent_limit', $this->appConfig->getAppValueInt('recent_limit', 100));
|
||||
|
||||
// File sorting user config
|
||||
$filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import type { FileStat, ResponseDataDetailed, SearchResult } from 'webdav'
|
|||
|
||||
import { getCurrentUser } from '@nextcloud/auth'
|
||||
import { Folder, Permission, davGetRecentSearch, davRootPath, davRemoteURL, davResultToNode } from '@nextcloud/files'
|
||||
import { loadState } from '@nextcloud/initial-state'
|
||||
import { CancelablePromise } from 'cancelable-promise'
|
||||
import { useUserConfigStore } from '../store/userconfig.ts'
|
||||
import { getPinia } from '../store/index.ts'
|
||||
|
|
@ -14,6 +15,7 @@ import { client } from './WebdavClient.ts'
|
|||
import { getBaseUrl } from '@nextcloud/router'
|
||||
|
||||
const lastTwoWeeksTimestamp = Math.round((Date.now() / 1000) - (60 * 60 * 24 * 14))
|
||||
const recentLimit = loadState<number>('files', 'recent_limit', 100)
|
||||
|
||||
/**
|
||||
* Helper to map a WebDAV result to a Nextcloud node
|
||||
|
|
@ -48,7 +50,7 @@ export const getContents = (path = '/'): CancelablePromise<ContentsWithRoot> =>
|
|||
const contentsResponse = await client.search('/', {
|
||||
signal: controller.signal,
|
||||
details: true,
|
||||
data: davGetRecentSearch(lastTwoWeeksTimestamp),
|
||||
data: davGetRecentSearch(lastTwoWeeksTimestamp, recentLimit),
|
||||
}) as ResponseDataDetailed<SearchResult>
|
||||
|
||||
const contents = contentsResponse.data.results
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use OCP\App\IAppManager;
|
|||
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
||||
use OCP\AppFramework\Http\RedirectResponse;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Services\IAppConfig;
|
||||
use OCP\AppFramework\Services\IInitialState;
|
||||
use OCP\Diagnostics\IEventLogger;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
|
|
@ -46,6 +47,7 @@ use Test\TestCase;
|
|||
class ViewControllerTest extends TestCase {
|
||||
private ContainerInterface&MockObject $container;
|
||||
private IAppManager&MockObject $appManager;
|
||||
private IAppConfig&MockObject $appConfig;
|
||||
private ICacheFactory&MockObject $cacheFactory;
|
||||
private IConfig&MockObject $config;
|
||||
private IEventDispatcher $eventDispatcher;
|
||||
|
|
@ -68,6 +70,7 @@ class ViewControllerTest extends TestCase {
|
|||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->appManager = $this->createMock(IAppManager::class);
|
||||
$this->appConfig = $this->createMock(IAppConfig::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$this->initialState = $this->createMock(IInitialState::class);
|
||||
|
|
@ -134,6 +137,7 @@ class ViewControllerTest extends TestCase {
|
|||
$this->userConfig,
|
||||
$this->viewConfig,
|
||||
$filenameValidator,
|
||||
$this->appConfig,
|
||||
])
|
||||
->onlyMethods([
|
||||
'getStorageInfo',
|
||||
|
|
|
|||
4
dist/files-init.js
vendored
4
dist/files-init.js
vendored
File diff suppressed because one or more lines are too long
2
dist/files-init.js.map
vendored
2
dist/files-init.js.map
vendored
File diff suppressed because one or more lines are too long
|
|
@ -151,7 +151,11 @@ class QuerySearchHelper {
|
|||
|
||||
$requestedFields = $this->searchBuilder->extractRequestedFields($searchQuery->getSearchOperation());
|
||||
|
||||
$joinExtendedCache = in_array('creation_time', $requestedFields) || in_array('upload_time', $requestedFields);
|
||||
$orderFields = array_map(fn ($order) => $order->getField(), $searchQuery->getOrder());
|
||||
|
||||
$joinExtendedCache = in_array('creation_time', $requestedFields)
|
||||
|| in_array('upload_time', $requestedFields)
|
||||
|| in_array('last_activity', $orderFields);
|
||||
|
||||
$query = $builder->selectFileCache('file', $joinExtendedCache);
|
||||
|
||||
|
|
|
|||
|
|
@ -351,6 +351,10 @@ class SearchBuilder {
|
|||
if ($field === 'mtime') {
|
||||
$field = $query->func()->add($field, $query->createNamedParameter(0));
|
||||
}
|
||||
|
||||
if ($field === 'last_activity') {
|
||||
$field = $query->func()->greatest('file.mtime', $query->createFunction('COALESCE(fe.upload_time, 0)'));
|
||||
}
|
||||
}
|
||||
$query->addOrderBy($field, $order->getDirection());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@ class SearchOrder implements ISearchOrder {
|
|||
return $a->getId() <=> $b->getId();
|
||||
case 'permissions':
|
||||
return $a->getPermissions() <=> $b->getPermissions();
|
||||
case 'last_activity':
|
||||
return $a->getLastActivity() <=> $b->getLastActivity();
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue