Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion includes/class-spacefast-sync-state.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,11 @@ private static function compare_and_swap_option( string $option, $expected, $nex
maybe_serialize( $expected )
)
);
// Raw SQL bypasses WordPress's option-cache maintenance. A failed CAS
// means another request changed the row, so the next retry must reload
// that newer value instead of comparing the same stale cached value.
wp_cache_delete( $option, 'options' );
if ( 1 === $updated ) {
wp_cache_delete( $option, 'options' );
return true;
}
return false;
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: spacefast
Tags: static site, headless cms, simply static, deployment
Requires at least: 6.5
Requires PHP: 8.1
Stable tag: 0.5.2
Stable tag: 0.5.3
License: GPLv2 or later

Publish a Simply Static export to Spacefast, or rebuild a headless site when WordPress content changes.
Expand Down Expand Up @@ -31,6 +31,9 @@ OAuth access is limited to the Team you authorize and the mode you choose. WordP

== Changelog ==

= 0.5.3 =
* Reload the WordPress option cache after a concurrent sync-state update so large publishes keep progressing.

= 0.5.2 =
* Keep large first-publish upload receipts intact for WordPress sites with thousands of files.

Expand Down
4 changes: 2 additions & 2 deletions spacefast-wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Spacefast
* Plugin URI: https://spacefast.com/
* Description: Publishes static WordPress exports or rebuilds a headless Spacefast site.
* Version: 0.5.2
* Version: 0.5.3
* Update URI: https://github.com/spacefast/wordpress
* Requires at least: 6.5
* Requires PHP: 8.1
Expand All @@ -14,7 +14,7 @@

defined( 'ABSPATH' ) || exit;

define( 'SPACEFAST_WORDPRESS_VERSION', '0.5.2' );
define( 'SPACEFAST_WORDPRESS_VERSION', '0.5.3' );
define( 'SPACEFAST_WORDPRESS_FILE', __FILE__ );

require_once __DIR__ . '/includes/class-spacefast-settings.php';
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function spacefast_accept( bool $condition, string $message ): void {
);

$plugin = get_plugin_data( WP_PLUGIN_DIR . '/spacefast-wordpress/spacefast-wordpress.php', false, false );
spacefast_accept( '0.5.2' === $plugin['Version'], 'Unexpected plugin version.' );
spacefast_accept( '0.5.3' === $plugin['Version'], 'Unexpected plugin version.' );
spacefast_accept( 'https://github.com/spacefast/wordpress' === $plugin['UpdateURI'], 'Update URI is missing.' );

Spacefast_Settings::disconnect();
Expand Down
22 changes: 19 additions & 3 deletions tests/behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
define( 'SPACEFAST_WORDPRESS_VERSION', '0.1.0-test' );

$GLOBALS['spacefast_options'] = array();
$GLOBALS['spacefast_cached_options'] = array();
$GLOBALS['spacefast_cache_enabled'] = array();
$GLOBALS['spacefast_scheduled'] = array();
$GLOBALS['spacefast_before_query'] = null;
$GLOBALS['spacefast_post_types'] = array();
Expand Down Expand Up @@ -50,6 +52,14 @@ function sanitize_key( string $value ): string {
return preg_replace( '/[^a-z0-9_\\-]/', '', strtolower( $value ) ) ?? '';
}
function get_option( string $name, $default = false ) {
if ( ! empty( $GLOBALS['spacefast_cache_enabled'][ $name ] ) ) {
if ( array_key_exists( $name, $GLOBALS['spacefast_cached_options'] ) ) {
return $GLOBALS['spacefast_cached_options'][ $name ];
}
$value = $GLOBALS['spacefast_options'][ $name ] ?? $default;
$GLOBALS['spacefast_cached_options'][ $name ] = $value;
return $value;
}
return $GLOBALS['spacefast_options'][ $name ] ?? $default;
}
function update_option( string $name, $value ): bool {
Expand Down Expand Up @@ -86,7 +96,9 @@ function wp_unschedule_event( int $timestamp, string $hook ): bool {
function maybe_serialize( $value ): string {
return serialize( $value );
}
function wp_cache_delete(): void {}
function wp_cache_delete( string $name ): void {
unset( $GLOBALS['spacefast_cached_options'][ $name ] );
}
function wp_json_encode( $value ): string {
return (string) json_encode( $value, JSON_UNESCAPED_SLASHES );
}
Expand Down Expand Up @@ -486,11 +498,13 @@ static function ( string $url, array $args ) use ( &$revoke_requests ): array {
)
);
$GLOBALS['spacefast_before_query'] = static function (): void {
$current = Spacefast_Sync_State::get();
$current = $GLOBALS['spacefast_options'][ Spacefast_Sync_State::OPTION ];
$current['desired'] = 2;
$current['event_id'] = 'event-two';
Spacefast_Sync_State::save( $current );
$GLOBALS['spacefast_options'][ Spacefast_Sync_State::OPTION ] = $current;
};
$GLOBALS['spacefast_cache_enabled'][ Spacefast_Sync_State::OPTION ] = true;
$GLOBALS['spacefast_cached_options'][ Spacefast_Sync_State::OPTION ] = Spacefast_Sync_State::get();
$cas_ack = Spacefast_Sync_State::mutate(
static fn( array $current ): array => Spacefast_Sync_State::acknowledge(
$current,
Expand All @@ -502,6 +516,8 @@ static function ( string $url, array $args ) use ( &$revoke_requests ): array {
check( 1 === $cas_ack['delivered'], 'CAS acknowledges only the delivered generation' );
check( 'event-two' === $cas_ack['event_id'], 'CAS preserves the successor event id' );
check( 'building' === $cas_ack['last_status'], 'CAS keeps the accepted build active while preserving its successor' );
unset( $GLOBALS['spacefast_cache_enabled'][ Spacefast_Sync_State::OPTION ] );
unset( $GLOBALS['spacefast_cached_options'][ Spacefast_Sync_State::OPTION ] );

$invalid_response = new Spacefast_Client(
static fn(): array => array(
Expand Down
Loading