Cache `attachment_url_to_postid()` lookups in `Optml_Lazyload_Replacer` to reduce database overhead
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 65/100
- Tipo di issue
- Refactoring
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Ambito
- performance
Direzione di ricerca
Start in the Optml_Lazyload_Replacer class (under the plugin's inc/ directory) and find every call site of attachment_url_to_postid() in its replacement pipeline, including the path used for /wp-json/wp/v2/... requests. Add a per-request static array keyed by URL, then a persistent layer via wp_cache_get/wp_cache_set or transients keyed by a hash of the URL, and confirm reuse by counting wp_postmeta queries (e.g. with Query Monitor) on a page with repeated images. Done looks like: repeated URL lookups hit the cache and postmeta query count drops for repeated content and REST hits.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Impact: 75 · Confidence: 90 · Complexity: 40
Description
Problem
When Optimole's Optml_Lazyload_Replacer processes content (including REST API endpoints like /wp-json/wp/v2/...), it repeatedly calls core WordPress attachment_url_to_postid() to resolve image URLs to attachment IDs. In WordPress core, attachment_url_to_postid() queries the wp_postmeta table directly without built-in persistent caching. On pages or API endpoints with multiple images, this results in dozen of expensive wp_postmeta DB queries, severely slowing down PHP request execution time (e.g., ~6.25 seconds spent on 28 postmeta queries in a single request).
Desired Behavior
Optimole should cache the mapping between image attachment URLs and attachment IDs using WordPress Object Cache / Transients, or optimize the replacer pipeline so attachment_url_to_postid() is only executed when strictly necessary and cached across requests.
Acceptance Criteria
Optml_Lazyload_Replacercaches URL-to-attachment ID resolutions in WP Object Cache / transient storage.- Duplicate image URL lookups within the same request lifecycle reuse in-memory cache.
- Database query count for
wp_postmetaduring lazyload replacement drops significantly for repeated content/API hits.
Customer Context
A premium user noticed via New Relic profiling that Optml_Lazyload_Replacer is executing repeated attachment_url_to_postid() calls during REST API requests, causing 28 wp_postmeta database queries consuming ~6.25s of a 7.98s transaction.
Root Cause Analysis
The customer is asking to prevent or cache repeated URL-to-attachment-ID lookups. Underlying cause: attachment_url_to_postid() is uncached in WordPress core, and Optml_Lazyload_Replacer executes it on every image URL encountered during content replacement. This is an architecture performance issue in how existing replacement functionality interacts with WP database lookups. Improving existing behavior by introducing transient/object caching or in-memory static caching around attachment_url_to_postid() within Optimole solves the root cause without adding configuration surface.
Alternative Suggestions
Wrap attachment_url_to_postid() calls in Optml_Lazyload_Replacer with an internal static array cache for single-request scope and WP Object Cache / Transients (keyed by URL hash) across requests to eliminate repetitive wp_postmeta queries.
Source: HelpScout #3524196151
Generated by feature-request-triage workflow (ID: feature-request-triage_6b0599ff05a6a1.02374250)
- Lingua principale
- PHP
- Stelle
- 74
- Fork
- 14
- Merge medio
- 1g 2h
- PR unite (30g)
- 35
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Codeinwp/optimole-wp
-
Lazyload SVG placeholder runs uncached attachment lookups with JSON-escaped URLs on REST responsesApertacustomer report
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Codeinwp/optimole-wp#1253 ·
I maintainer di solito rispondono entro 1 giorno
-
customer report feature-request-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Codeinwp/optimole-wp#1239 ·
I maintainer di solito rispondono entro 1 giorno
-
Page profiler never stores above-the-fold background images: `b` is always sent with empty selector mapsForse già presa @girishpanchal30 l’ha presa 19 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
Codeinwp/optimole-wp#1216 · 5 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Throttle and optimize `/wp-json/optml/v1/optimizations` REST API endpoint execution and validationApertacustomer report feature-request-triage
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
Codeinwp/optimole-wp#1250 ·
I maintainer di solito rispondono entro 1 giorno
-
customer report feature-request-triage
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
Codeinwp/optimole-wp#1231 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Codeinwp/optimole-wp
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
HE-Arc/le-panier-du-coin#49 ·
I maintainer di solito rispondono entro 1 giorno
-
15.0
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
bug: juros do parcelamento travados em 1x no gateway Rede Débito e Crédito 3DS (woo-rede 5.6.0)Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
LinkNacional/woo-rede#367 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno