Skip to content

Add drop-in response-time measurement snippet for CB routes - #34

Open
datengraben wants to merge 5 commits into
masterfrom
claude/response-time-measurement-eiy957
Open

Add drop-in response-time measurement snippet for CB routes#34
datengraben wants to merge 5 commits into
masterfrom
claude/response-time-measurement-eiy957

Conversation

@datengraben

Copy link
Copy Markdown
Owner

No description provided.

claude added 5 commits July 11, 2026 18:34
- Cache::getCacheItem() now fires commonsbooking_cache_hit/_miss actions
- response timer groups requests by route derived from URL/query (ajax
  action, REST path, or CPT context) instead of raw URL
- switches default output to NDJSON written to a dedicated log file
- drops the https-only gate so local/staging load tests are captured
- derive_payload(): generic sanitized snapshot of $_REQUEST (array
  values collapsed to counts, noise keys denylisted), so hot-route
  params (date range, item/location ids, ...) are captured without
  per-route parsing
- derive_db_stats(): turns on $wpdb->save_queries at init and reads
  query_count/time_ms/slowest_ms/slowest_sql from $wpdb->queries at
  shutdown - the central point where SQL is actually emitted; slowest
  query SQL is literal-normalized for grouping and to avoid leaking
  data values into the log
- both are filterable (cb_response_timer_payload_denylist,
  cb_response_timer_track_queries) and off by default overhead is
  documented in the file header
…h writes

- Adds a lazily-created {$wpdb->prefix}cb_response_timer table (dbDelta
  + versioned option, same pattern as BookingCodes::initBookingCodesTable)
  with an essentials schema for segmentation: route, duration_ms,
  cache_hits/misses, db_query_count/time_ms, and a payload JSON column
- The default sink now appends a trimmed row to a queue file per request
  (cheap, same cost as before) instead of writing the full NDJSON record
- A WP-Cron job (cb_response_timer_flush, default every 300s) atomically
  rotates the queue file and bulk-inserts pending rows in one multi-row
  INSERT per chunk of 500, so no request pays for a synchronous DB write
- url/post_type/slowest_sql/slowest_ms are still computed and passed
  through the cb_response_timer_measured action for custom listeners,
  just dropped from the built-in SQL persistence layer
…xport

- Drops the file/cron queue entirely: each measured request now does one
  direct $wpdb->insert() into {$wpdb->prefix}cb_response_timer - zero
  setup, no dependency on WP-Cron actually firing (tradeoff vs the
  earlier deferred-write design documented in the file header)
- Adds ip and user_agent columns; the IP is redacted (last octet for
  IPv4, last colon-group for IPv6) before it's ever computed or stored -
  the raw IP never exists outside $_SERVER
- Adds a CSV export at GET /cb-response-timer/{secret}/export.csv,
  matched directly against the request path (no rewrite rule, nothing
  to flush) and streamed in chunks so it scales with table size
- The secret is a plugin variable: define CB_RESPONSE_TIMER_SECRET in
  wp-config.php, or let it auto-generate and persist as an option for
  zero-setup use; overridable via cb_response_timer_export_secret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants