Skip to content

Conversation

@elzody
Copy link
Contributor

@elzody elzody commented Apr 28, 2025

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

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

This comment was marked as outdated.

@elzody

This comment was marked as outdated.

@elzody elzody force-pushed the feat/template-field-extraction-improvements branch from 9112dce to 4f8e51e Compare May 14, 2025 21:17
@skjnldsv
Copy link
Member

Awesome, thanks for this!
The code looks good 👍

@susnux susnux added the pending documentation This pull request needs an associated documentation update label May 15, 2025
@susnux
Copy link
Contributor

susnux commented May 15, 2025

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

@elzody elzody force-pushed the feat/template-field-extraction-improvements branch from 4e5780c to 18de6fd Compare May 16, 2025 20:39
@github-project-automation github-project-automation bot moved this to 🧭 Planning evaluation (don't pick) in 📝 Office team May 19, 2025
@elzody elzody moved this from 🧭 Planning evaluation (don't pick) to 🏗️ In progress in 📝 Office team May 19, 2025
Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
@elzody elzody force-pushed the feat/template-field-extraction-improvements branch from 18de6fd to 5c7216f Compare May 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
Contributor Author

elzody commented May 19, 2025

/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 owner May 19, 2025 23:04
@elzody elzody merged commit 99148e9 into master May 19, 2025
193 checks passed
@elzody elzody deleted the feat/template-field-extraction-improvements branch May 19, 2025 23:23
@github-project-automation github-project-automation bot moved this from 🏗️ In progress to ☑️ Done in 📝 Office team May 19, 2025
@juliusknorr
Copy link
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
Member

/backport to stable31

@pedropintosilva
Copy link

Awesome, thanks 🥳

@mmeeks
Copy link

mmeeks commented May 21, 2025

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
Contributor Author

elzody commented May 21, 2025

@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

mmeeks commented May 21, 2025

Wonderful =) thanks Elizabeth.

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

Labels

3. to review Waiting for reviews bug feature: files feature: templates javascript pending documentation This pull request needs an associated documentation update performance 🚀 php Pull 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