Skip to content

Commit 701902d

Browse files
feat(recent-files): add recent_files_limit config on files settings
Signed-off-by: Cristian Scheid <cristianscheid@gmail.com>
1 parent 44175e3 commit 701902d

7 files changed

Lines changed: 69 additions & 7 deletions

File tree

apps/files/lib/Service/UserConfig.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ class UserConfig {
7979
'default' => true,
8080
'allowed' => [true, false],
8181
],
82+
[
83+
// Maximum number of files to display in the recent section
84+
'key' => 'recent_files_limit',
85+
'default' => 100,
86+
'min' => 1,
87+
'max' => 100,
88+
],
8289
];
8390
protected ?IUser $user = null;
8491

@@ -118,7 +125,7 @@ private function getAllowedConfigValues(string $key): array {
118125
* Get the default config value for a given key
119126
*
120127
* @param string $key a valid config key
121-
* @return string|bool
128+
* @return string|bool|int
122129
*/
123130
private function getDefaultConfigValue(string $key) {
124131
foreach (self::ALLOWED_CONFIGS as $config) {
@@ -146,7 +153,13 @@ public function setConfig(string $key, $value): void {
146153
throw new \InvalidArgumentException('Unknown config key');
147154
}
148155

149-
if (!in_array($value, $this->getAllowedConfigValues($key))) {
156+
$config = $this->getConfigDefinition($key);
157+
158+
if (isset($config['min'], $config['max'])) {
159+
if ((int)$value < $config['min'] || (int)$value > $config['max']) {
160+
throw new \InvalidArgumentException('Invalid config value');
161+
}
162+
} elseif (!in_array($value, $this->getAllowedConfigValues($key))) {
150163
throw new \InvalidArgumentException('Invalid config value');
151164
}
152165

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

180193
return array_combine($this->getAllowedConfigKeys(), $userConfigs);
181194
}
195+
196+
/**
197+
* Get the config definition for a given key
198+
*
199+
* @param string $key
200+
* @return array
201+
*/
202+
private function getConfigDefinition(string $key): array {
203+
foreach (self::ALLOWED_CONFIGS as $config) {
204+
if ($config['key'] === $key) {
205+
return $config;
206+
}
207+
}
208+
return [];
209+
}
182210
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!--
2+
- SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
- SPDX-License-Identifier: AGPL-3.0-or-later
4+
-->
5+
6+
<script lang="ts" setup>
7+
import { t } from '@nextcloud/l10n'
8+
import { NcInputField } from '@nextcloud/vue'
9+
import debounce from 'debounce'
10+
import NcAppSettingsSection from '@nextcloud/vue/components/NcAppSettingsSection'
11+
import NcFormBox from '@nextcloud/vue/components/NcFormBox'
12+
import { useUserConfigStore } from '../../store/userconfig.ts'
13+
14+
const store = useUserConfigStore()
15+
const debouncedUpdate = debounce((value: number) => {
16+
store.update('recent_files_limit', value)
17+
}, 500)
18+
</script>
19+
20+
<template>
21+
<NcAppSettingsSection id="recent" :name="t('files', 'Recent view')">
22+
<NcFormBox>
23+
<NcInputField
24+
v-model="store.userConfig.recent_files_limit"
25+
type="number"
26+
:min="1"
27+
:max="100"
28+
:label="t('files', 'Maximum number of files shown in the Recent view')"
29+
@update:model-value="debouncedUpdate(Number($event))" />
30+
</NcFormBox>
31+
</NcAppSettingsSection>
32+
</template>

apps/files/src/services/Recent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function getContents(path = '/', options: { signal: AbortSignal }):
4141
const contentsResponse = await client.search('/', {
4242
signal: options.signal,
4343
details: true,
44-
data: getRecentSearch(lastTwoWeeksTimestamp),
44+
data: getRecentSearch(lastTwoWeeksTimestamp, store.userConfig.recent_files_limit),
4545
}) as ResponseDataDetailed<SearchResult>
4646

4747
const contents = contentsResponse.data.results

apps/files/src/store/userconfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const initialUserConfig = loadState<UserConfig>('files', 'config', {
2323
show_mime_column: true,
2424
sort_favorites_first: true,
2525
sort_folders_first: true,
26+
recent_files_limit: 100,
2627

2728
show_dialog_deletion: false,
2829
show_dialog_file_extension: true,

apps/files/src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ export interface PathOptions {
5151

5252
// User config store
5353
export interface UserConfig {
54-
[key: string]: boolean | string | undefined
54+
[key: string]: boolean | string | number | undefined
5555

5656
crop_image_previews: boolean
5757
default_view: 'files' | 'personal'
5858
folder_tree: boolean
5959
grid_view: boolean
6060
sort_favorites_first: boolean
6161
sort_folders_first: boolean
62+
recent_files_limit: number
6263

6364
show_files_extensions: boolean
6465
show_hidden: boolean

apps/files/src/views/FilesAppSettings.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import NcAppSettingsDialog from '@nextcloud/vue/components/NcAppSettingsDialog'
1111
import FilesAppSettingsAppearance from '../components/FilesAppSettings/FilesAppSettingsAppearance.vue'
1212
import FilesAppSettingsGeneral from '../components/FilesAppSettings/FilesAppSettingsGeneral.vue'
1313
import FilesAppSettingsLegacyApi from '../components/FilesAppSettings/FilesAppSettingsLegacyApi.vue'
14+
import FilesAppSettingsRecent from '../components/FilesAppSettings/FilesAppSettingsRecent.vue'
1415
import FilesAppSettingsShortcuts from '../components/FilesAppSettings/FilesAppSettingsShortcuts.vue'
1516
import FilesAppSettingsWarnings from '../components/FilesAppSettings/FilesAppSettingsWarnings.vue'
1617
import FilesAppSettingsWebDav from '../components/FilesAppSettings/FilesAppSettingsWebDav.vue'
@@ -57,6 +58,7 @@ async function showKeyboardShortcuts() {
5758
<FilesAppSettingsLegacyApi />
5859
<FilesAppSettingsWarnings />
5960
<FilesAppSettingsWebDav />
61+
<FilesAppSettingsRecent />
6062
<FilesAppSettingsShortcuts />
6163
</NcAppSettingsDialog>
6264
</template>

lib/private/Files/Cache/QuerySearchHelper.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array
153153

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

156-
$joinExtendedCache = in_array('creation_time', $requestedFields) || in_array('upload_time', $requestedFields);
157-
158-
$query = $builder->selectFileCache('file', $joinExtendedCache);
156+
$query = $builder->selectFileCache('file', true);
159157

160158
if (in_array('systemtag', $requestedFields)) {
161159
$this->equipQueryForSystemTags($query, $this->requireUser($searchQuery));

0 commit comments

Comments
 (0)