Skip to content

Commit 765e767

Browse files
committed
make sure snapshots don't all have the exact same snapshot_date
1 parent eeaffca commit 765e767

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

includes/snapshot-tools.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,16 +530,23 @@ private static function save_snapshots( array $snapshots )
530530

531531
global $wpdb;
532532
$table_name = $wpdb->prefix . self::$table_name;
533-
$now = ( new DateTime() )->format( 'Y-m-d H:i:s' );
533+
$now = new DateTime();
534534

535535
$logged_data = false;
536+
$counter = 0;
536537
foreach ( $filtered_snapshots as $snapshot ) {
537538
if ( empty( $snapshot['post_id'] ) || empty( $snapshot['post_type'] )
538539
|| empty( $snapshot['period'] ) || empty( $snapshot['period_start'] )
539540
|| empty( $snapshot['period_end'] ) || empty( $snapshot['period_interval'] ) ) {
540541
continue;
541542
}
542543

544+
$snapshot_date = clone $now;
545+
if ( $counter >= 50 ) {
546+
$seconds_to_subtract = floor( $counter / 50 );
547+
$snapshot_date->modify( "-$seconds_to_subtract seconds" );
548+
}
549+
543550
$data = [
544551
'post_id' => $snapshot['post_id'],
545552
'post_type' => $snapshot['post_type'],
@@ -549,8 +556,9 @@ private static function save_snapshots( array $snapshots )
549556
'period_end' => $snapshot['period_end']->format( 'Y-m-d H:i:s' ),
550557
'period_interval' => $snapshot['period_interval'],
551558
'post_content' => wp_json_encode( $snapshot['post_content'] ?? [] ),
552-
'snapshot_date' => $now
559+
'snapshot_date' => $snapshot_date->format( 'Y-m-d H:i:s' )
553560
];
561+
$counter++;
554562
if ( !$logged_data ) {
555563
// dt_write_log( 'Saving data: ' . json_encode( $data ) );
556564
$logged_data = true;

0 commit comments

Comments
 (0)