Skip to content

feat: only get template fields once selected - #52514

Merged
elzody merged 4 commits into
masterfrom
feat/template-field-extraction-improvements
May 19, 2025
Merged

feat: only get template fields once selected#52514
elzody merged 4 commits into
masterfrom
feat/template-field-extraction-improvements

Conversation

@elzody

@elzodyelzody commented Apr 28, 2025

Copy link
Copy Markdown
Contributor

Summary

Creating a new file from a template can take a very long time if browser cache is disabled, does not exist yet, or an incognito session is used. This is because the TemplatePicker.vue component requests all templates from the /ocs/v2.php/apps/files/api/v1/templates endpoint, which includes all the extracted fields of each template. For office documents, this meant that, for each template file, a request was being made to Collabora one after the other, causing very poor performance. I tried to find a workaround for this in the richdocuments app (e.g. using concurrent requests), but was not able to find a viable solution that made a noticeable difference in performance.

My solution is to add a new property to the BeforeGetTemplatesEvent class, indicating whether or not the template fields should be extracted. This allows more fine-grained control, as if you only want the templates but don't want to waste compute or wait on I/O to extract the template fields, you can pass false as a value for withFields, which is the default. If you do want the fields, you pass true. This is used for the new endpoint, so the front end can call it to get the fields for whatever template is selected.

You can find the related richdocuments pull request above, which includes tests.

Screen Recordings

Performance before
template-picker-slow-loading.mp4
Performance after
template-picker-fast-loading.mp4

Checklist

@elzodyelzody self-assigned this Apr 28, 2025
@elzody
elzody requested review from a team, provokateurin and skjnldsv as code ownersApril 28, 2025 19:46
@elzody
elzody requested review from come-nc, nfebe and susnux and removed request for a teamApril 28, 2025 19:46
come-nc

This comment was marked as outdated.

@elzody

This comment was marked as outdated.

@elzody
elzodyforce-pushed the feat/template-field-extraction-improvements branch from 9112dce to 4f8e51eCompareMay 14, 2025 21:17
@skjnldsv

Copy link
Copy Markdown
Member

Awesome, thanks for this!
The code looks good 👍

Comment threadlib/public/Files/Template/BeforeGetTemplatesEvent.php Outdated
@susnuxsusnux added the pending documentation This pull request needs an associated documentation update label May 15, 2025
@susnux

Copy link
Copy Markdown
Contributor

OCP changes need to be documented in the app upgrade guides in the developer docs afterwards

@elzody
elzodyforce-pushed the feat/template-field-extraction-improvements branch from 4e5780c to 18de6fdCompareMay 16, 2025 20:39
@github-project-automationgithub-project-automationBot moved this to 🧭 Planning evaluation (don't pick) in 📝 Productivity teamMay 19, 2025
@elzodyelzody moved this from 🧭 Planning evaluation (don't pick) to 🏗️ In progress in 📝 Productivity teamMay 19, 2025
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
@elzody
elzodyforce-pushed the feat/template-field-extraction-improvements branch from 18de6fd to 5c7216fCompareMay 19, 2025 21:56
elzody added 2 commits May 19, 2025 18:19
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
@elzody

Copy link
Copy Markdown
ContributorAuthor

/compile

Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
@nextcloud-command
nextcloud-command requested a review from a team as a code ownerMay 19, 2025 23:04
@elzody
elzody merged commit 99148e9 into masterMay 19, 2025
@elzody
elzody deleted the feat/template-field-extraction-improvements branch May 19, 2025 23:23
@github-project-automationgithub-project-automationBot moved this from 🏗️ In progress to ☑️ Done in 📝 Productivity teamMay 19, 2025
@juliusknorr

Copy link
Copy Markdown
Member

Just noticed now, I would have marked as a bugfix, @elzody Since the backport would need manual adjustments to be backward compatible with 31 can you take care of that?

@juliusknorr

Copy link
Copy Markdown
Member

/backport to stable31

@pedropintosilva

Copy link
Copy Markdown

Awesome, thanks 🥳

@mmeeks

Copy link
Copy Markdown

Great to see the fix - thanks ! =) I had always assumed we just cached large thumbnails of the templates in the object store (as I assume we do for the file thumbnail view) and serve / re-use those for the template selector - is that not the case ?

@elzody

Copy link
Copy Markdown
ContributorAuthor

@mmeeks The issue was not the thumbnails, but rather the fact that we send each of those templates to Collabora for field/content control extraction via the extract/transform API. It was taking a long time to process those, so now it just skips that when displaying them, and will only send the template to have the content controls extracted once the user selects which one they want to use.

And of course, once the content controls are returned, we cache them on our side for the future, unless the template file itself changes (in which case we re-fetch them because they might have changed), or after a certain amount of time (I forgot how long off the top of my head).

@mmeeks

Copy link
Copy Markdown

Wonderful =) thanks Elizabeth.

@skjnldsvskjnldsv mentioned this pull request Aug 19, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to reviewWaiting for reviewsbugfeature: filesfeature: templatesjavascriptpending documentationThis pull request needs an associated documentation updateperformance 🚀phpPull requests that update Php code

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

File templates showing very slow

9 participants

@elzody@skjnldsv@susnux@juliusknorr@pedropintosilva@mmeeks@come-nc@tobiasKaminsky@nextcloud-command