Skip to content

[Bug]: files_reminders causing N+1 queries for folders with more than 512 elements #61193

@salmart-dev

Description

@salmart-dev

⚠️ This issue respects the following points: ⚠️

Bug description

Summary

OCA\FilesReminders\Dav\PropFindPlugin preloads reminders information for an entire collection during PROPFIND requests. ReminderService has a cacheFolder method which uses CappedMemoryCache as cache. The problem is that the default size for this cache is 512 meaning that if a directory has more than 512 files inside we start getting cache misses and start querying the DB.

What's worse is that once the condition hits, it always voids the pre-cached data and causes N+1 queries because:

  • the preload mechanism starts caching reminders for all files in a directory
  • once the limit of the CappedMemoryCache is reached, the information that was cached earlier is discarded
  • when the PROPFIND is serialized into XML, the first file is no longer in the cache, causing a query for the single file
  • the result is cached, pushing another older result out of the cache

Steps to reproduce

  1. Create a folder
  2. Upload more than 512 files
  3. Do a PROPFIND request on the folder
  4. See that the code runs >512 queries targeting the reminders table

Expected behavior

Queries are executed in N+1 way only if there are more than 512 reminders in files in a folder.

Nextcloud Server version

35 (master)

Operating system

None

PHP engine version

None

Web server

None

Database engine version

None

Is this bug present after an update or on a fresh install?

None

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?

  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other

Configuration report

List of activated Apps

Nextcloud Signing status

Nextcloud Logs

Additional info

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    Status
    Confirmed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions