Skip to content

feat(recent-files): add recent_files_limit config on files settings#58761

Draft
cristianscheid wants to merge 1 commit intomasterfrom
feat/1700/limit-recent-files
Draft

feat(recent-files): add recent_files_limit config on files settings#58761
cristianscheid wants to merge 1 commit intomasterfrom
feat/1700/limit-recent-files

Conversation

@cristianscheid
Copy link
Contributor

@cristianscheid cristianscheid commented Mar 6, 2026

  • Resolves: #

Summary

  • Adds recent_files_limit option to the Files settings menu, persisted in the oc_preferences table.
  • Allows users to dynamically configure the maximum number of items displayed in the Recent tab of the Files app.
  • The limit is passed as a parameter to getRecentSearchCustom() method from the library counterpart at nextcloud-libraries/nextcloud-files.

Visuals

Screencast.from.06-03-2026.18.53.02.webm

TODO

  • As it is right now, the frontend part can pass the limit correctly but the frontend still asks for the backend to order by <d:getlastmodified/>.
  • lib/private/Files/Node/Folder::search() receives the order by parameter and does the sorting calling lib/private/Files/Search/SearchOrder::sortFileInfoNoDirection(), which does not take into consideration upload time, leaving recently uploaded files that have older modification dates at the bottom, and depending on the limit set, out of the list.
// lib/private/Files/Search/SearchOrder.php

public function sortFileInfo(FileInfo $a, FileInfo $b): int {
	$cmp = $this->sortFileInfoNoDirection($a, $b);
	return $cmp * ($this->direction === ISearchOrder::DIRECTION_ASCENDING ? 1 : -1);
}

private function sortFileInfoNoDirection(FileInfo $a, FileInfo $b): int {
	switch ($this->field) {
		case 'name':
			return $a->getName() <=> $b->getName();
		case 'mimetype':
			return $a->getMimetype() <=> $b->getMimetype();
		case 'mtime':
			return $a->getMtime() <=> $b->getMtime();
		case 'size':
			return $a->getSize() <=> $b->getSize();
		case 'fileid':
			return $a->getId() <=> $b->getId();
		case 'permissions':
			return $a->getPermissions() <=> $b->getPermissions();
		default:
			return 0;
	}
}

Open Questions

  • Would it make sense to introduce a new <nc:last_activity> DAV attribute that resolves to max(uploadTime, mtime), ensuring that recently uploaded files with an older mtime have their upload_time considered instead, giving a more accurate recencly ordering?
  • Alternatively, maybe we could reuse <nc:upload_time/> and the frontend could request to order by it, resolving as max(uploadTime, mtime) internally when sorting, avoiding a new attribute altogether:
// lib/private/Files/Search/SearchOrder.php

private function sortFileInfoNoDirection(FileInfo $a, FileInfo $b): int {
    switch ($this->field) {
        [...]
        case 'upload_time':
            $timeA = max($a->getUploadTime(), $a->getMtime());
            $timeB = max($b->getUploadTime(), $b->getMtime());
            return $timeA <=> $timeB;
        [...]
    }
}

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Signed-off-by: Cristian Scheid <cristianscheid@gmail.com>
@cristianscheid cristianscheid force-pushed the feat/1700/limit-recent-files branch from 7631ec7 to da37572 Compare March 6, 2026 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant