Skip to content

fix(files): reload mimetypes once per unknown id - #67681

Open
kukanggg89 wants to merge 1 commit into
nextcloud:masterfrom
kukanggg89:fix-mimetype-loader-reload-67153
Open

kukanggg89 wants to merge 1 commit into
nextcloud:masterfrom
kukanggg89:fix-mimetype-loader-reload-67153

Conversation

@kukanggg89

Copy link
Copy Markdown
Contributor

Summary

Long-running processes only read oc_mimetypes from the database once. After the first database read, Loader kept serving its in-memory copy, so a mimetype another process added later stayed invisible: getMimetypeById() returned null and the file fell back to application/octet-stream. That is how a running occ fulltextsearch:live ended up indexing fresh .txt files with empty content on a new instance.

Loader now keeps track of the ids and mimetypes that already triggered a reload, and goes back to the database once per unknown id or mimetype. This follows the direction from the issue discussion. exists() gets the same treatment, since it had the same stale read and getId() relies on it. A row added later is picked up on the next lookup, and a genuinely unknown id still costs at most one extra query. reset() clears the tracking along with the loaded data.

Two tests cover it in tests/lib/Files/Type/LoaderTest.php, using the same loader instance throughout: one for a mimetype inserted directly in the database after the first lookup, one for exists() finding a mimetype added the same way.

I could not run the tests here (no PHP on this machine), so the repo CI has the final say.

TODO

  • n/a - no follow-up work left in this PR

Checklist

  • Code is properly formatted
  • Sign-off message is added to all commits
  • Tests (unit, integration, api and/or acceptance) are included (added, but not run locally, see Summary)
  • Screenshots before/after for front-end changes - n/a, no front-end change
  • Documentation (manuals or wiki) has been updated or is not required - n/a, no user-facing behaviour to document
  • Backports requested where applicable (ex: critical bugfixes)
  • Labels added where applicable (ex: bug/enhancement, 3. to review, feature component)
  • Milestone added for target branch/version (ex: 32.x for stable32)

AI (if applicable)

Drafted with help from Claude. I reviewed and revised every change myself before opening this PR.

Loader::getMimetypeById() and exists() only went back to the database while $loadedFromDatabase was false, and loadMimetypes() set that flag on the first database read. A long-running process never saw rows another process added later, so getMimetypeById() returned null and files of that type fell back to application/octet-stream.

Track the ids and mimetypes that already triggered a reload and go back to the database once per unknown id or mimetype. A row added later is picked up on the next lookup, and a genuinely unknown id still costs at most one extra query.

Signed-off-by: parel <farelalfarizi89@gmail.com>
Assisted-by: Muse:Muse Spark 1.3
@kukanggg89
kukanggg89 requested a review from a team as a code owner December 4, 2026 07:34
@kukanggg89
kukanggg89 requested review from icewind1991 and leftybournes and removed request for a team December 4, 2026 07:34

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant