feat: implement WooCommerce AJAX product search
This commit is contained in:
@@ -41,7 +41,19 @@
|
||||
- `System Status` reports: PHP/WP/WC versions, active plugins, asset sizes, transient hit rate.
|
||||
- Lighthouse CI optional (not required for v1).
|
||||
|
||||
## 8. Anti-Patterns Forbidden
|
||||
## 8. Search Performance (M3)
|
||||
|
||||
- **Debounce**: 250ms in `assets/js/search.js:debounce` (200–300ms target). Prevents request on every keystroke.
|
||||
- **Min length**: 2 chars (handler returns empty without query). Input `data-min-length`.
|
||||
- **Bounded**: `limit` default 6, max 20, validated; handler over-fetches `limit*2` for dedup then slices to `limit`; max 40 IDs scanned.
|
||||
- **Stale protection**: `AbortController` cancels previous fetch + monotonic `seq` counter ignores stale JSON; rapid `iph → iphone` cannot overwrite newer.
|
||||
- **Dedupe**: identical query (`lastQuery`) reopens dropdown without fetch.
|
||||
- **Query**: `WP_Query` `s` + `_sku` LIKE, `post_status publish`, `no_found_rows`, `fields ids`, no N+1, `wc_get_product` only for returned IDs (≤6).
|
||||
- **Asset**: `search.js` enqueued only on front-end where `data-xshop-search` exists (header on all front-end pages, guarded via `initAll`); `woo.css` global intentional.
|
||||
- **Caching**: server `Cache-Control: public, max-age=60`; no client cache beyond in-memory `lastQuery` (no stale invalidation issues).
|
||||
- **Payload**: minimal 6 items × 6 fields (~2KB JSON).
|
||||
|
||||
## 9. Anti-Patterns Forbidden
|
||||
|
||||
- Global `wp_enqueue_script` without condition.
|
||||
- Querying all products to compute filters.
|
||||
|
||||
Reference in New Issue
Block a user