Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 8, 2025

Adds test coverage to validate cache behavior when updating a network's domain/path via the update_network() function.

Changes:

  • Add test coverage: Added test_update_network_clears_cache() test case to validate that cache is properly cleared after network update
public function test_update_network_clears_cache() {
    // Create a test network.
    $network_id = $this->factory->network->create(
        array(
            'domain' => 'example.com',
            'path'   => '/test/',
        )
    );

    // Get the network to populate cache.
    $network = get_network( $network_id );
    $this->assertEquals( 'example.com', $network->domain, 'Network should have original domain' );
    $this->assertEquals( '/test/', $network->path, 'Network should have original path' );

    // Update the network with new domain and path.
    $result = update_network( $network_id, 'newdomain.com', '/newpath/' );
    $this->assertTrue( $result, 'Network update should succeed' );

    // Get the network again - it should reflect the updated values.
    $updated_network = get_network( $network_id );
    $this->assertEquals( 'newdomain.com', $updated_network->domain, 'Network should have updated domain without manual cache flush' );
    $this->assertEquals( '/newpath/', $updated_network->path, 'Network should have updated path without manual cache flush' );
}

This test ensures that the cache clearing mechanism works correctly when a network's domain and path are updated.

Original prompt

This section details on the original issue you should resolve

<issue_title>Sticky cache after changing a network's domain/path</issue_title>
<issue_description>After changing the domain/path of a network via

function update_network( $id, $domain, $path = '' ) {
, the old URL was still being populated via
$domain = ! empty( $network->domain )
until running wp_cache_flush.

We run clean_network_cache, which sounds like it should take care of it, but didn't. Still digging around on it.</issue_description>

Comments on the Issue (you are @copilot in this section)

@JJJ I've made a few modifications here.

Instead of calling refresh_blog_details() we are now calling clean_blog_cache() directly.

Curious if you have a better experience once 2.5.0 is released. 🙏</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix sticky cache after changing a network's domain/path Clear network cache before domain/path update to prevent stale entries Dec 8, 2025
Copilot AI requested a review from JJJ December 8, 2025 23:36
@JJJ
Copy link
Collaborator

JJJ commented Dec 9, 2025

@copilot Keep the tests but remove the changes to update_network() as they aren't quite right.

Copy link
Contributor Author

Copilot AI commented Dec 9, 2025

@copilot Keep the tests but remove the changes to update_network() as they aren't quite right.

Reverted the update_network() changes in commit 2ed5b68. The test has been kept.

Copilot AI changed the title Clear network cache before domain/path update to prevent stale entries Add test coverage for network cache clearing on domain/path update Dec 9, 2025
@JJJ JJJ marked this pull request as ready for review December 9, 2025 00:24
Copilot AI review requested due to automatic review settings December 9, 2025 00:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds test coverage to validate that network cache is properly cleared when updating a network's domain and path through the update_network() function. This test addresses a previously reported issue where cache would remain stale after network updates, requiring manual cache flushing.

  • Adds test_update_network_clears_cache() to verify cache clearing behavior
  • Tests the complete update flow: create network, populate cache, update network, verify updated values
  • Validates that the clean_network_cache() call in update_network() works correctly

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JJJ JJJ merged commit 9fceb64 into master Dec 9, 2025
26 checks passed
@JJJ JJJ deleted the copilot/fix-sticky-cache-issue branch December 9, 2025 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sticky cache after changing a network's domain/path

2 participants