Skip to content

perf: drop per-request MIME registration from the App constructor (#108) - #125

Merged
Jaggob merged 2 commits into
mainfrom
refactor/108-mime-boot
Jun 5, 2026
Merged

perf: drop per-request MIME registration from the App constructor (#108)#125
Jaggob merged 2 commits into
mainfrom
refactor/108-mime-boot

Conversation

@Jaggob

@Jaggob Jaggob commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

What

Application::__construct ran IMimeTypeDetector::getAllMappings() + registerType() on every app instantiation. Two problems:

  • registerType() isn't part of the public OCP\Files\IMimeTypeDetector interface (it's a concrete-class method), and
  • getAllMappings() forces loading the full mapping table each time — avoidable per-request cost.

Change

Remove the runtime registration entirely (not just move it to boot()). The .pad MIME type is already registered persistently by the RegisterMimeType repair step — config mimetypemapping.json + mimetypealiases.json, filecache backfill, and the core filetype icon — which is the supported Nextcloud mechanism and the actual source of truth. The runtime call merely duplicated that for the current request. Constructor now only calls parent::__construct, with a comment explaining why no MIME work lives here.

Approach informed by how Text / Richdocuments / Whiteboard handle MIME (config mapping + repair, no runtime registerType), and the fact that registerType isn't public OCP API.

Acceptance

  • No MIME work in the constructor
  • .pad still detected as application/x-etherpad-nextcloud

Verification

  • PHPUnit 403 + Psalm green (baseline shrank by 1 — the UndefinedInterfaceMethod entry for the non-public registerType() call is gone).
  • Deployed to NC 33; full Playwright suite 23 passed, 0 flaky.pad detection still works in the Files list, viewer, and template picker.

Closes #108.

…#108)

Application::__construct ran IMimeTypeDetector::getAllMappings() +
registerType() on every app instantiation. registerType() isn't even part of
the public OCP\Files\IMimeTypeDetector interface, and getAllMappings() forces
loading the full mapping table each time.

The .pad MIME type is already registered persistently by the RegisterMimeType
repair step (config mimetypemapping.json + mimetypealiases.json, filecache
backfill, core filetype icon) — the supported Nextcloud mechanism. The runtime
call was redundant with that, so remove it and keep the constructor clean.

Verified on NC 33: .pad still detected as application/x-etherpad-nextcloud
(Files list, viewer, template picker). PHPUnit 403 + Psalm green (baseline -1:
the UndefinedInterfaceMethod entry for the non-public registerType() is gone);
full Playwright 23/23.

Closes #108.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes per-request MIME type registration from the app Application constructor, relying solely on Nextcloud’s supported persistent MIME registration mechanism (repair steps + config mapping/aliases + filecache updates). This reduces runtime overhead and eliminates use of a non-public IMimeTypeDetector method.

Changes:

  • Removed IMimeTypeDetector::getAllMappings() / registerType() calls from Application::__construct().
  • Updated the constructor with an explanatory comment documenting why runtime MIME registration is intentionally absent.
  • Dropped the corresponding Psalm baseline entry for the non-public registerType() call.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/AppInfo/Application.php Removes runtime MIME registration from the constructor and documents the rationale.
psalm-baseline.xml Removes the baseline suppression that was only needed due to the non-public registerType() usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…MimeType)

Review follow-up on #125: the MIME repair steps had no targeted unit tests.
Add the high-value, genuinely unit-testable slices; the filesystem / \OC
config-dir / icon-copy parts stay covered by e2e.

- RegisterMimeType: extract the idempotent config merge into a pure
  mergeMimeMappings() helper and test it — preserves unrelated entries, is
  idempotent on re-run, and corrects a stale value for our own key.
- BackfillPadMimeType: fake-QueryBuilder test (mirrors BindingServiceTest)
  for the two skip branches (pad mime / application mimepart missing) and the
  update path, asserting the idempotency guard (only rows whose mimetype is
  not already the pad mime) and the *.pad name filter.

Behaviour-preserving (the merge helper is the same array_replace_recursive).
PHPUnit 409 + Psalm green.
@Jaggob
Jaggob merged commit ea657d0 into main Jun 5, 2026
13 checks passed
@Jaggob
Jaggob deleted the refactor/108-mime-boot branch June 17, 2026 14:35
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.

Register the pad MIME type in boot() instead of the App constructor

2 participants