-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Full sync: Set chunk size of comments dynamically (#41350)
* Move filter_objects_and_metadata_by_size to module class and use it by posts and comments * changelog * Fixed tests * changelog * ID for comments is not an int so let's cast before comparing * Added tests for comments * Id field for posts is ID * Added tests to cover filter_objects_and_metadata_by_size * Replace deprecated method * Typo in docblocks
- Loading branch information
Showing
8 changed files
with
404 additions
and
65 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/packages/sync/changelog/update-full-sync-comments-dynamically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Sync: Full Sync comments now send dynamic chunks if chunk size default is too big |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
projects/packages/sync/tests/php/modules/test-module.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName | ||
|
||
/** | ||
* Test file for Automattic\Jetpack\Sync\Modules\Module | ||
* | ||
* @package automattic/jetpack-masterbar | ||
*/ | ||
|
||
namespace Automattic\Jetpack\Sync; | ||
|
||
use WorDBless\BaseTestCase; | ||
|
||
/** | ||
* Class Test_Module | ||
* | ||
* @covers Automattic\Jetpack\Sync\Modules\Module | ||
*/ | ||
class Test_Module extends BaseTestCase { | ||
|
||
/** | ||
* The module instance. | ||
* | ||
* @var \Automattic\Jetpack\Sync\Modules\Module | ||
*/ | ||
private $module_instance; | ||
|
||
/** | ||
* Runs before every test in this class. | ||
*/ | ||
protected function setUp(): void { | ||
parent::setUp(); | ||
$this->module_instance = $this->getMockBuilder( 'Automattic\Jetpack\Sync\Modules\Module' ) | ||
->onlyMethods( array( 'id_field', 'name' ) ) | ||
->getMock(); | ||
$this->module_instance->method( 'id_field' )->willReturn( 'ID' ); | ||
$this->module_instance->method( 'name' )->willReturn( 'module' ); | ||
} | ||
/** | ||
* Test filter_objects_and_metadata_by_size with no constraints of size | ||
*/ | ||
public function filter_objects_and_metadata_by_size_no_constraints() { | ||
$objects = array( | ||
(object) array( | ||
'ID' => 1, | ||
'module_title' => 'Post 1', | ||
), | ||
); | ||
$metadata = array( | ||
(object) array( | ||
'module_id' => 1, | ||
'meta_value' => 'meta1', | ||
), | ||
); | ||
|
||
$result = $this->module_instance->filter_objects_and_metadata_by_size( 'module', $objects, $metadata, PHP_INT_MAX, PHP_INT_MAX ); | ||
|
||
$this->assertCount( 1, $result[0] ); | ||
$this->assertCount( 1, $result[1] ); | ||
$this->assertCount( 1, $result[2] ); | ||
} | ||
/** | ||
* Test filter_objects_and_metadata_by_size with constraints of size for metadata | ||
*/ | ||
public function test_filter_objects_exceeding_max_meta_size() { | ||
$objects = array( | ||
(object) array( | ||
'ID' => 1, | ||
'module_title' => 'Post 1', | ||
), | ||
); | ||
$metadata = array( | ||
(object) array( | ||
'module_id' => 1, | ||
'meta_value' => str_repeat( 'a', 100 ), | ||
), | ||
); | ||
|
||
$result = $this->module_instance->filter_objects_and_metadata_by_size( 'module', $objects, $metadata, 50, 200 ); | ||
|
||
$this->assertSame( '', $result[2][0]->meta_value ); | ||
} | ||
/** | ||
* Test filter_objects_and_metadata_by_size with constraints of size for total size | ||
*/ | ||
public function test_filter_objects_exceeding_max_total_size() { | ||
$objects = array( | ||
(object) array( | ||
'ID' => 1, | ||
'module_title' => 'Post 1', | ||
), | ||
(object) array( | ||
'ID' => 2, | ||
'module_title' => 'Post 2', | ||
), | ||
); | ||
$metadata = array( | ||
(object) array( | ||
'module_id' => 1, | ||
'meta_value' => 'meta1', | ||
), | ||
); | ||
|
||
$result = $this->module_instance->filter_objects_and_metadata_by_size( 'module', $objects, $metadata, 50, 10 ); | ||
|
||
$this->assertCount( 1, $result[0] ); // Should only include the first object | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/update-full-sync-comments-dynamically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: other | ||
|
||
Sync: Full Sync comments now send dynamic chunks if chunk size default is too big |
Oops, something went wrong.