PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
← All changes | jetpack_vendor/automattic/jetpack-sync/src/class-rest-sender.php +18 -10 12.2.3 → 16.3-beta View file →
@@ -25,11 +25,11 @@
25 25
26 26 /**
27 27 * Checkout objects from the queue
28 28 *
29 - * @param string $queue_name Name of Queue.
30 - * @param int $number_of_items Number of Items.
31 - * @param array $args arguments.
29 + * @param string $queue_name Name of Queue.
30 + * @param int|null $number_of_items Number of Items. Null for memory-based checkout.
31 + * @param array $args Request arguments. Supports 'pop', 'force', 'encode', and 'use_memory_limit'.
32 32 *
33 33 * @return array|WP_Error
34 34 */
35 35 public function queue_pull( $queue_name, $number_of_items, $args ) {
@@ -61,9 +61,9 @@
61 61 if ( ! is_object( $buffer ) ) {
62 62 return new WP_Error( 'buffer_non-object', 'Buffer is not an object', 400 );
63 63 }
64 64
65 - $encode = isset( $args['encode'] ) ? $args['encode'] : true;
65 + $encode = $args['encode'] ?? true;
66 66
67 67 Settings::set_is_syncing( true );
68 68 list( $items_to_send, $skipped_items_ids ) = $sender->get_items_to_send( $buffer, $encode );
69 69 Settings::set_is_syncing( false );
@@ -73,8 +73,9 @@
73 73 'items' => $items_to_send,
74 74 'skipped_items' => $skipped_items_ids,
75 75 'codec' => $encode ? $sender->get_codec()->name() : null,
76 76 'sent_timestamp' => time(),
77 + 'queue_size' => $queue->size(),
77 78 );
78 79 }
79 80
80 81 /**
@@ -115,24 +116,32 @@
115 116
116 117 /**
117 118 * Checkout items out of the sync queue.
118 119 *
119 - * @param Queue $queue Sync Queue.
120 - * @param int $number_of_items Number of items to checkout.
120 + * @param Queue $queue Sync Queue.
121 + * @param int|null $number_of_items Number of items to checkout. When null, uses memory-based checkout with default settings.
121 122 *
122 - * @return WP_Error
123 + * @return Queue_Buffer|WP_Error
123 124 */
124 125 protected function get_buffer( $queue, $number_of_items ) {
125 126 $start = time();
126 127 $max_duration = 5; // this will try to get the buffer.
127 128
128 - $buffer = $queue->checkout( $number_of_items );
129 + $use_memory_limit = null === $number_of_items;
130 + $memory_limit = $use_memory_limit ? Settings::get_setting( 'dequeue_max_bytes' ) : null;
131 + $max_rows = $use_memory_limit ? Settings::get_setting( 'upload_max_rows' ) : null;
132 +
133 + $buffer = $use_memory_limit
134 + ? $queue->checkout_with_memory_limit( $memory_limit, $max_rows )
135 + : $queue->checkout( $number_of_items );
129 136 $duration = time() - $start;
130 137
131 138 while ( is_wp_error( $buffer ) && $duration < $max_duration ) {
132 139 sleep( 2 );
133 140 $duration = time() - $start;
134 - $buffer = $queue->checkout( $number_of_items );
141 + $buffer = $use_memory_limit
142 + ? $queue->checkout_with_memory_limit( $memory_limit, $max_rows )
143 + : $queue->checkout( $number_of_items );
135 144 }
136 145
137 146 if ( false === $buffer ) {
138 147 return new WP_Error( 'queue_size', 'The queue is empty and there is nothing to send', 400 );
@@ -139,6 +148,5 @@
139 148 }
140 149
141 150 return $buffer;
142 151 }
143 -
144 152 }