Skip to content
Draft
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
32 changes: 30 additions & 2 deletions apps/files/lib/Service/UserConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ class UserConfig {
'default' => true,
'allowed' => [true, false],
],
[
// Maximum number of files to display in the recent section
'key' => 'recent_files_limit',
'default' => 100,
'min' => 1,
'max' => 100,
],
];
protected ?IUser $user = null;

Expand Down Expand Up @@ -118,7 +125,7 @@ private function getAllowedConfigValues(string $key): array {
* Get the default config value for a given key
*
* @param string $key a valid config key
* @return string|bool
* @return string|bool|int
*/
private function getDefaultConfigValue(string $key) {
foreach (self::ALLOWED_CONFIGS as $config) {
Expand Down Expand Up @@ -146,7 +153,13 @@ public function setConfig(string $key, $value): void {
throw new \InvalidArgumentException('Unknown config key');
}

if (!in_array($value, $this->getAllowedConfigValues($key))) {
$config = $this->getConfigDefinition($key);

if (isset($config['min'], $config['max'])) {
if ((int)$value < $config['min'] || (int)$value > $config['max']) {
throw new \InvalidArgumentException('Invalid config value');
}
} elseif (!in_array($value, $this->getAllowedConfigValues($key))) {
throw new \InvalidArgumentException('Invalid config value');
}

Expand Down Expand Up @@ -179,4 +192,19 @@ public function getConfigs(): array {

return array_combine($this->getAllowedConfigKeys(), $userConfigs);
}

/**
* Get the config definition for a given key
*
* @param string $key
* @return array
*/
private function getConfigDefinition(string $key): array {
foreach (self::ALLOWED_CONFIGS as $config) {
if ($config['key'] === $key) {
return $config;
}
}
return [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--
- SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->

<script lang="ts" setup>
import { t } from '@nextcloud/l10n'
import { NcInputField } from '@nextcloud/vue'
import debounce from 'debounce'
import NcAppSettingsSection from '@nextcloud/vue/components/NcAppSettingsSection'
import NcFormBox from '@nextcloud/vue/components/NcFormBox'
import { useUserConfigStore } from '../../store/userconfig.ts'

const store = useUserConfigStore()
const debouncedUpdate = debounce((value: number) => {
store.update('recent_files_limit', value)
}, 500)
</script>

<template>
<NcAppSettingsSection id="recent" :name="t('files', 'Recent view')">
<NcFormBox>
<NcInputField
v-model="store.userConfig.recent_files_limit"
type="number"
:min="1"
:max="100"
:label="t('files', 'Maximum number of files shown in the Recent view')"
@update:model-value="debouncedUpdate(Number($event))" />
</NcFormBox>
</NcAppSettingsSection>
</template>
2 changes: 1 addition & 1 deletion apps/files/src/services/Recent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function getContents(path = '/', options: { signal: AbortSignal }):
const contentsResponse = await client.search('/', {
signal: options.signal,
details: true,
data: getRecentSearch(lastTwoWeeksTimestamp),
data: getRecentSearch(lastTwoWeeksTimestamp, store.userConfig.recent_files_limit),
}) as ResponseDataDetailed<SearchResult>

const contents = contentsResponse.data.results
Expand Down
1 change: 1 addition & 0 deletions apps/files/src/store/userconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const initialUserConfig = loadState<UserConfig>('files', 'config', {
show_mime_column: true,
sort_favorites_first: true,
sort_folders_first: true,
recent_files_limit: 100,

show_dialog_deletion: false,
show_dialog_file_extension: true,
Expand Down
3 changes: 2 additions & 1 deletion apps/files/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ export interface PathOptions {

// User config store
export interface UserConfig {
[key: string]: boolean | string | undefined
[key: string]: boolean | string | number | undefined

crop_image_previews: boolean
default_view: 'files' | 'personal'
folder_tree: boolean
grid_view: boolean
sort_favorites_first: boolean
sort_folders_first: boolean
recent_files_limit: number

show_files_extensions: boolean
show_hidden: boolean
Expand Down
2 changes: 2 additions & 0 deletions apps/files/src/views/FilesAppSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import NcAppSettingsDialog from '@nextcloud/vue/components/NcAppSettingsDialog'
import FilesAppSettingsAppearance from '../components/FilesAppSettings/FilesAppSettingsAppearance.vue'
import FilesAppSettingsGeneral from '../components/FilesAppSettings/FilesAppSettingsGeneral.vue'
import FilesAppSettingsLegacyApi from '../components/FilesAppSettings/FilesAppSettingsLegacyApi.vue'
import FilesAppSettingsRecent from '../components/FilesAppSettings/FilesAppSettingsRecent.vue'
import FilesAppSettingsShortcuts from '../components/FilesAppSettings/FilesAppSettingsShortcuts.vue'
import FilesAppSettingsWarnings from '../components/FilesAppSettings/FilesAppSettingsWarnings.vue'
import FilesAppSettingsWebDav from '../components/FilesAppSettings/FilesAppSettingsWebDav.vue'
Expand Down Expand Up @@ -57,6 +58,7 @@ async function showKeyboardShortcuts() {
<FilesAppSettingsLegacyApi />
<FilesAppSettingsWarnings />
<FilesAppSettingsWebDav />
<FilesAppSettingsRecent />
<FilesAppSettingsShortcuts />
</NcAppSettingsDialog>
</template>
4 changes: 1 addition & 3 deletions lib/private/Files/Cache/QuerySearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array

$requestedFields = $this->searchBuilder->extractRequestedFields($searchQuery->getSearchOperation());

$joinExtendedCache = in_array('creation_time', $requestedFields) || in_array('upload_time', $requestedFields);

$query = $builder->selectFileCache('file', $joinExtendedCache);
$query = $builder->selectFileCache('file', true);

if (in_array('systemtag', $requestedFields)) {
$this->equipQueryForSystemTags($query, $this->requireUser($searchQuery));
Expand Down
Loading