Cache `attachment_url_to_postid()` lookups in `Optml_Lazyload_Replacer` to reduce database overhead
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 65/100
- issue の種類
- リファクタリング
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 領域
- performance
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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)
- 主要言語
- PHP
- スター
- 74
- フォーク
- 14
- 平均マージ
- 1日 2時間
- マージ済み PR(30日)
- 35
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Codeinwp/optimole-wp のほかの issue
-
Lazyload SVG placeholder runs uncached attachment lookups with JSON-escaped URLs on REST responsesオープンcustomer report
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Codeinwp/optimole-wp#1253 ·
メンテナーはふだん 1 日以内に返信
-
customer report feature-request-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Codeinwp/optimole-wp#1239 ·
メンテナーはふだん 1 日以内に返信
-
Page profiler never stores above-the-fold background images: `b` is always sent with empty selector maps対応中かも @girishpanchal30 が 19 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
Codeinwp/optimole-wp#1216 · コメント 5 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Throttle and optimize `/wp-json/optml/v1/optimizations` REST API endpoint execution and validationオープンcustomer report feature-request-triage
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
Codeinwp/optimole-wp#1250 ·
メンテナーはふだん 1 日以内に返信
-
customer report feature-request-triage
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
Codeinwp/optimole-wp#1231 ·
メンテナーはふだん 1 日以内に返信
Codeinwp/optimole-wp の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
HE-Arc/le-panier-du-coin#49 ·
メンテナーはふだん 1 日以内に返信
-
15.0
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
bug: juros do parcelamento travados em 1x no gateway Rede Débito e Crédito 3DS (woo-rede 5.6.0)オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
LinkNacional/woo-rede#367 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信