Lazyload SVG placeholder runs uncached attachment lookups with JSON-escaped URLs on REST responses
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 72/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Área
- backend, performance
Línea de trabajo
Empieza en inc/tag_replacer.php alrededor de la línea 304, donde el img_url sin procesar se pasa a optml_tag_replace, luego lee Optml_Lazyload_Replacer::get_svg_for() y sus llamadas a is_file() / attachment_url_to_post_id(). Reproduce habilitando Lazyload y el color de placeholder genérico, luego solicitando /wp-json/wp/v2/posts/<id> sin sesión mientras observas las consultas a wp_postmeta. Hecho significa que el placeholder de REST tiene las dimensiones reales y no se ejecutan búsquedas de _wp_attached_file contra la URL escapada para JSON.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Reported in: https://secure.helpscout.net/conversation/3524196151/501323
On REST requests, Optml_Manager::process_template_redirect_content() buffers the whole JSON body, and Optml_Tag_Replacer passes the raw escaped img_url (https:\/\/...) to the optml_tag_replace filter (inc/tag_replacer.php:304). Optml_Lazyload_Replacer::get_svg_for() then calls is_file() and attachment_url_to_post_id() with that escaped URL. The file check fails and all 4 attachment_url_to_postid() variants miss (the www variant is also a no-op, since :// is not present in an escaped URL). ID 0 is cached for 10 minutes, so the lookups repeat after that.
Steps to reproduce (4.2.20)
- Enable Lazyload and "Enable generic placeholder color".
- Add an attachment image without width/height attributes to a post.
- Request
/wp-json/wp/v2/posts/<id>while logged out.
Expected
The placeholder uses the real dimensions, as it does on the front end.
Actual
A 100% x 100% SVG placeholder, plus 4 wp_postmeta queries per image matching the escaped URL:
SELECT post_id, meta_value FROM wp_postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = 'http:\\/\\/localhost:8955\\/wp-content\\/uploads\\/2026\\/11\\/chart.jpg'
SELECT post_id, meta_value FROM wp_postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = 'http:\\/\\/localhost:8955\\/wp-content\\/uploads\\/2026\\/11\\/chart-scaled.jpg'
(same two again for the www variant)
| Request | Placeholder | _wp_attached_file queries |
|---|---|---|
| Front end | 2200 x 360 (correct) | 0 |
| REST | 100% x 100% (fallback) | 4 per image |
| REST, generic placeholder disabled | blurred preview | 0 |
On the reporter's site (large wp_postmeta table, Memcached object cache) one REST request for a custom post type made 29 wp_postmeta queries taking 6.25 s of a 7.98 s transaction, traced in New Relic through Optml_Lazyload_Replacer::get_svg_for > attachment_url_to_post_id.
Workaround
Disable "Enable generic placeholder color" (Settings > Advanced > Lazyload).
Suggested fix
Unslash the URL before get_svg_for() and the attachment lookup. Use the wp-image-<ID> class when it is present, before any URL lookup.
Related: #1249
- Lenguaje dominante
- PHP
- Estrellas
- 74
- Forks
- 14
- Merge medio
- 1 d 2 h
- PR fusionados (30 d)
- 35
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Codeinwp/optimole-wp
-
customer report feature-request-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Codeinwp/optimole-wp#1239 ·
Los mantenedores suelen responder en 1 día
-
Page profiler never stores above-the-fold background images: `b` is always sent with empty selector mapsPosiblemente ocupada @girishpanchal30 la tomó hace 19 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Codeinwp/optimole-wp#1216 · 5 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Throttle and optimize `/wp-json/optml/v1/optimizations` REST API endpoint execution and validationAbiertocustomer report feature-request-triage
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
Codeinwp/optimole-wp#1250 ·
Los mantenedores suelen responder en 1 día
-
Cache `attachment_url_to_postid()` lookups in `Optml_Lazyload_Replacer` to reduce database overheadAbiertocustomer report feature-request-triage
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
Codeinwp/optimole-wp#1249 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
customer report feature-request-triage
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Codeinwp/optimole-wp#1231 ·
Los mantenedores suelen responder en 1 día
Todos los issues de Codeinwp/optimole-wp
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
HE-Arc/le-panier-du-coin#49 ·
Los mantenedores suelen responder en 1 día
-
15.0
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
bug: juros do parcelamento travados em 1x no gateway Rede Débito e Crédito 3DS (woo-rede 5.6.0)Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
LinkNacional/woo-rede#367 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Problems with button inputSuffixAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día