I've added performance profiling to the logs page. Here's how to identify what's slow:
Navigate to: SourceHub → Activity Logs
The profiling will output to your WordPress debug log. Check:
/wp-content/debug.log(if WP_DEBUG_LOG is enabled)- Or your server's error log
[SourceHub Performance] Logs Page - Total: X.XXs | Logs Query: X.XXs | Count: X.XXs | Stats: X.XXs | Total Logs: XXXX
If "Logs Query" is slow (>5 seconds):
- Problem: The main query to fetch logs is slow
- Likely cause: Too many log entries or missing database indexes
- Solution: Add more indexes or implement log archiving
If "Count" is slow (>5 seconds):
- Problem: Counting total logs is slow
- Likely cause: Full table scan on large table
- Solution: Cache the count or add index
If "Stats" is slow (>5 seconds):
- Problem: Statistics aggregation is slow
- Likely cause: GROUP BY query on large dataset
- Solution: Cache stats or limit date range
If template rendering is slow (Total >> sum of queries):
- Problem: PHP processing in the view template
- Likely cause: Too much data being processed in loops
- Solution: Optimize template or reduce data
SELECT COUNT(*) FROM wp_sourcehub_logs;If you have >100,000 logs, that's the problem.
SELECT MAX(LENGTH(data)) as max_data_size, AVG(LENGTH(data)) as avg_data_size
FROM wp_sourcehub_logs;If max_data_size > 100KB, large JSON blobs are slowing things down.
The indexes should exist on:
created_atstatusconnection_idstatus_created (status, created_at)- compositeaction_created (action, created_at)- composite
In get_formatted_logs(), we decode JSON for every log entry:
'data' => !empty($log->data) ? json_decode($log->data, true) : array(),If you have 20 logs with 50KB JSON each, that's 1MB of JSON parsing.
In admin/class-sourcehub-admin.php line 427:
$per_page = 10; // Reduce from 20Remove JSON decoding from get_formatted_logs() and only decode when viewing details.
Run the cleanup function regularly:
SourceHub_Database::clean_old_logs(30); // Keep only 30 daysCache the stats query result for 5 minutes using WordPress transients.
- Load the logs page
- Check the debug output
- Report back which query is slow
- I'll provide a targeted fix