Cache `attachment_url_to_postid()` lookups in `Optml_Lazyload_Replacer` to reduce database overhead
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 65/100
- Loại issue
- Tái cấu trúc
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- performance
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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)
- Ngôn ngữ chính
- PHP
- Star
- 74
- Fork
- 14
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 35
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Codeinwp/optimole-wp
-
Lazyload SVG placeholder runs uncached attachment lookups with JSON-escaped URLs on REST responsesĐang mởcustomer report
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Codeinwp/optimole-wp#1253 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
customer report feature-request-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Codeinwp/optimole-wp#1239 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Page profiler never stores above-the-fold background images: `b` is always sent with empty selector mapsCó thể đã có người làm @girishpanchal30 đã nhận 19 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Codeinwp/optimole-wp#1216 · 5 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Throttle and optimize `/wp-json/optml/v1/optimizations` REST API endpoint execution and validationĐang mởcustomer report feature-request-triage
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
Codeinwp/optimole-wp#1250 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
customer report feature-request-triage
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Codeinwp/optimole-wp#1231 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Codeinwp/optimole-wp
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
HE-Arc/le-panier-du-coin#49 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
15.0
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
bug: juros do parcelamento travados em 1x no gateway Rede Débito e Crédito 3DS (woo-rede 5.6.0)Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
LinkNacional/woo-rede#367 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Problems with button inputSuffixĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày