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

fix/170v2: add filter to delay post saving. #173

Merged
merged 3 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion assets/js/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class ConvertToBlocksEditorSupport {
return null;
}

client.save();
setTimeout(() => {
client.save();
}, config.agent.save_delay);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Sidsector9 Lets add a JS fallback to 0 in case the BE doesn't send this var. Sometimes this happens on large migrations when the BE stalls. If save_delay is 0, then call save directly instead of using the setTimeout.


return null;
}, 500);
Expand Down
8 changes: 7 additions & 1 deletion includes/ConvertToBlocks/MigrationAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ public function register() {
return;
}

$posts_to_update = get_option( 'ctb_posts_to_update' );
$cursor = get_option( 'ctb_cursor' );
$posts_to_update = is_array( $posts_to_update ) ? $posts_to_update : [];
$post_id = $posts_to_update[ $cursor ] ?? 0;

wp_localize_script(
'convert_to_blocks_editor',
'convert_to_blocks_agent',
[
'agent' => [
'next' => $this->next(),
'next' => $this->next(),
'save_delay' => apply_filters( 'convert_to_blocks_save_delay', 500, $post_id )
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Sidsector9 Lets change this to 0, or there is no delay to match the legacy behaviour. For context, 500 ms adds hours to a migration that has 100k posts.

],
]
);
Expand Down
Loading