v2.4.1 - Graph query optimized (~150k rows → ~576 rows)
WP VisitChart v2.4.1
Performance fix: traffic graph now loads significantly faster.
Before
The graph query fetched ~150,000 raw heartbeat rows and grouped them into 5-minute buckets in PHP. For each row, PHP computed the bucket boundary, maintained arrays of unique session_id and session_id + post_id values, then counted them. This took over 1 second on a busy site.
After
Aggregation now happens entirely in SQL:
SELECT
FROM_UNIXTIME(
FLOOR(UNIX_TIMESTAMP(created_at) / 300) * 300, '%H:%i'
) AS time_label,
DATE(created_at) AS day,
COUNT(DISTINCT session_id) AS visitors,
COUNT(DISTINCT CONCAT(session_id, '-', post_id)) AS pageviews
FROM wp_lstats_heartbeats
WHERE is_bot = 0 AND source = 'heartbeat'
AND (...date ranges...)
GROUP BY day, time_label
ORDER BY day, time_label ASC;FLOOR(UNIX_TIMESTAMP / 300) * 300 rounds down to the nearest 5-minute boundary directly in MySQL. The query returns ~576 rows (288 buckets × 2 days) instead of ~150,000. PHP now only builds the fixed 288-slot array from a pre-aggregated lookup — no raw row iteration.
Upgrade
Download wp-visitchart.zip below and replace the existing plugin files. No database changes required.