Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM: Mailpoet Sync issue with the sync percentage calculation #37508

Merged
merged 2 commits into from
May 23, 2024

Conversation

cleacos
Copy link
Contributor

@cleacos cleacos commented May 23, 2024

Resolves https://github.com/Automattic/zero-bs-crm/issues/3223
Resolves https://github.com/Automattic/zero-bs-crm/issues/3462

Proposed changes:

This PR resolved the issue we had with the MailPoet Sync, calculating the complete percentage of the job. The sync process works well, the issue was about calculating the total percentage of the work. Specificaly it was about how the calculation code was handling the pagination, the current page goes from 0 to (total_page - 1), and the calculation code was interpreting the current page as 1 to total_page range, so that was the reason because it seems stuck in the latest page.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

  • Install MailPoet
  • Active the MailPoet Sync module at JPCRM
  • Add a bunch of subscribers. You can use the import section on MailPoet: /wp-admin/admin.php?page=mailpoet-import#/step_method_selection and select the Paste the data into a text box method. With the help of ChatGPT create a list of 126 subscribers:
Follow this serie, I need 126 lines:

1@example.com, T1, TT1
2@example.com, T2, TT2

I copied and pated it for you here: 348ba-pb

  • Then run the JPCRM sync. Everything should go well...
    image

The debug output data should match with the expected. If you get 66% re-load the page, and it will complete it. MailPoet Sync runs one page per sync job, so you have to refresh it.

@cleacos cleacos self-assigned this May 23, 2024
@cleacos cleacos requested a review from gogdzl May 23, 2024 11:02
Copy link
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.

@cleacos cleacos marked this pull request as ready for review May 23, 2024 11:13
// check for completion
$total_page_count = $this->get_total_page_count();
if ( $page_no >= $total_page_count ) {
if ( $page_no >= ( $total_page_count - 1 ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$page_no works in the 0..(total_pages - 1) range and $total_page_count in the 1..total_pages range.

// set pointer to last page
$this->set_resume_from_page( $total_page_count );
// set pointer to last processed page
$this->set_resume_from_page( $page_no );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to set the latest processed page here, not the total, that is total_pages - 1 or $page_no

$this->debug( 'Pages completed: ' . $this->current_page . ' / ' . $this->mailpoet_total_pages );
$this->debug( 'Subscribers completed: ' . min( $this->current_page * $this->subscribers_per_page, $this->mailpoet_total_subscribers ) . ' / ' . $this->mailpoet_total_subscribers );
$this->debug( 'Percentage completed: ' . $percentage_completed . '%' );
$this->debug( 'Pages completed: ' . ( $this->current_page + 1 ) . ' / ' . $this->mailpoet_total_pages );
Copy link
Contributor Author

@cleacos cleacos May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to match ranges, so the current page should be increased +1 for this debug info.

$total_pages = (int)$percentage_counts['total_pages'];
$total_remaining_pages = $percentage_counts['total_pages'] - $percentage_counts['page_no'];

$total_remaining_pages = $percentage_counts['total_pages'] - ( $percentage_counts['page_no'] + 1 );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to match the same page range, so we have to increase the page_no +1.

@gogdzl
Copy link
Contributor

gogdzl commented May 23, 2024

It gets stuck at 0% for a single page import, but all contacts are imported successfully:

image

image

Copy link
Contributor

@gogdzl gogdzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my previous comment.

@gogdzl gogdzl self-requested a review May 23, 2024 13:32
Copy link
Contributor

@gogdzl gogdzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works!

image

@cleacos cleacos merged commit 5dda7f2 into trunk May 23, 2024
59 of 60 checks passed
@cleacos cleacos deleted the fix/3462-crm-mailpoet-sync-pagination-issue branch May 23, 2024 13:45
@github-actions github-actions bot added this to the crm/6.4.3 milestone May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[CRM] MailPoet Module [Plugin] CRM Issues about the Jetpack CRM plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants