# La lista de plantillas tarda entre 5 y 10 segundos en cargarse

**URL:** https://meta.discourse.org/t/template-list-takes-5-10-seconds-to-load/283361
**Category:** Support
**Tags:** templates
**Created:** [20 Octubre, 2023 05:57 UTC](https://meta.discourse.org/t/template-list-takes-5-10-seconds-to-load/283361 "2023-10-20T05:57:47Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![bartv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bartv/32/130052_2.png) [@bartv](https://meta.discourse.org/u/bartv)
#### Post date: [20 Octubre, 2023 05:57 UTC](https://meta.discourse.org/t/template-list-takes-5-10-seconds-to-load/283361/1 "2023-10-20T05:57:47Z")

</div>

En nuestra instancia, cargar la lista de plantillas suele ser bastante lento (piense en 5-10 segundos), o incluso falla después de una larga espera con un error 502. Tenemos un total de 15 plantillas y, aparte de esto, nuestro Discourse funciona bien. ¿Alguna idea?

---

<div class="post-metadata">

### Author: ![bartv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bartv/32/130052_2.png) [@bartv](https://meta.discourse.org/u/bartv)
#### Post date: [25 Octubre, 2023 05:52 UTC](https://meta.discourse.org/t/template-list-takes-5-10-seconds-to-load/283361/2 "2023-10-25T05:52:19Z")

</div>

¿Alguien? Estamos en un apuro, ya que las respuestas predeterminadas están rotas y esto tampoco nos funciona…

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [25 Octubre, 2023 06:15 UTC](https://meta.discourse.org/t/template-list-takes-5-10-seconds-to-load/283361/3 "2023-10-25T06:15:17Z")

</div>

Me temo que estoy un poco perdido con esto. Tenemos muchas más de 15 plantillas y la lista de plantillas se carga sin problemas.

¿Hay algo especial en alguna de tus plantillas? ¿Podrías deslistarlas todas y volver a listarlas una por una para ver si eso revela algo? (Deslistarlas debería eliminarlas de la lista activa).

---

<div class="post-metadata">

### Author: ![bartv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bartv/32/130052_2.png) [@bartv](https://meta.discourse.org/u/bartv)
#### Post date: [25 Octubre, 2023 06:28 UTC](https://meta.discourse.org/t/template-list-takes-5-10-seconds-to-load/283361/4 "2023-10-25T06:28:20Z")

</div>

¡Ah, creo que estás en lo correcto! Incluso acceder a la categoría que contiene mis plantillas provoca cargas muy lentas o fallos 😬 He despublicado todos los temas y deshabilitado el plugin de Plantillas, pero el problema persiste.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [25 Octubre, 2023 06:31 UTC](https://meta.discourse.org/t/template-list-takes-5-10-seconds-to-load/283361/5 "2023-10-25T06:31:28Z")

</div>

Hmmm. 🤔 ¿Tienes algún plugin que pueda estar en conflicto por el nombre ‘Plantilla’ de alguna manera? ¿La carga lenta en esa categoría todavía persiste en modo seguro?

---

<div class="post-metadata">

### Author: ![bartv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bartv/32/130052_2.png) [@bartv](https://meta.discourse.org/u/bartv)
#### Post date: [25 Octubre, 2023 06:33 UTC](https://meta.discourse.org/t/template-list-takes-5-10-seconds-to-load/283361/6 "2023-10-25T06:33:17Z")

</div>

Sí, solo estaba probando eso; el mismo problema en modo seguro. Intentaré crear una nueva categoría y mover algunas plantillas allí, a ver si eso soluciona las cosas.

---

<div class="post-metadata">

### Author: ![bartv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bartv/32/130052_2.png) [@bartv](https://meta.discourse.org/u/bartv)
#### Post date: [25 Octubre, 2023 06:40 UTC](https://meta.discourse.org/t/template-list-takes-5-10-seconds-to-load/283361/7 "2023-10-25T06:40:30Z")

</div>

¡Eso lo solucionó! Gracias por orientarme en la dirección correcta 🙂

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [25 Octubre, 2023 08:04 UTC](https://meta.discourse.org/t/template-list-takes-5-10-seconds-to-load/283361/8 "2023-10-25T08:04:02Z")

</div>

¿Te gustaría compartir qué fue lo que se rompió? Por si acaso alguien más tiene problemas similares.

---

<div class="post-metadata">

### Author: ![bartv](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bartv/32/130052_2.png) [@bartv](https://meta.discourse.org/u/bartv)
#### Post date: [25 Octubre, 2023 08:45 UTC](https://meta.discourse.org/t/template-list-takes-5-10-seconds-to-load/283361/9 "2023-10-25T08:45:47Z")

</div>

No pasé tiempo investigándolo y simplemente descarté la categoría antigua.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [24 Noviembre, 2023 08:46 UTC](https://meta.discourse.org/t/template-list-takes-5-10-seconds-to-load/283361/10 "2023-11-24T08:46:28Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [31 Enero, 2024 16:53 UTC](https://meta.discourse.org/t/template-list-takes-5-10-seconds-to-load/283361/11 "2024-01-31T16:53:01Z")

</div>

Creo que podemos haber encontrado la causa de esto, para futuros viajeros. Creo que debería arreglarse cuando esto se fusione: 🥳

> <https://github.com/discourse/discourse-templates/pull/67>
>
> Some communities were noticing that fetching the list of templates was very slow….
> This issue wouldn't just affect the templates form, but also browsing the templates category and
> 
> Most of the communities didn't look like they were affected but in some with extreme cases, this was causing 502 errors.
> The problem also seemed intermittent, with the slowness going away completely without any special action.
> 
> Upon inspecting a particularly affected instance, the problem was narrowed down to the list of subcategories from the categories templates that was repeating the same \`id\` multiple times.
> 
> The issue was tracked to a line that was mutating an array returned by the method \`Category.subcategory\_ids\` and prepending an item. Unfortunately, the result of this method was cached in the \`DistributedCache\` and mutating the array was causing the cached value to pile up the same category \`id\` in the array.
> 
> This caused the database queries that used the value returned for this function to become slow over time when the argument was the templates category. The busier the Community, the worst the problem would get.
> 
> This commit removes the \`prepend\` that was causing the issue.
