Skip to content

Conversation

@miguelpeixe
Copy link
Member

@miguelpeixe miguelpeixe commented Dec 13, 2024

Implements support for short-circuiting the distribution post meta update if it's not valid. Also implements support for distributing a post if a post meta changes, given we're also syncing them.

Because of the data event dispatch on post meta updates, there can be multiple dispatches in a single post save, if it includes multiple post meta updates. To prevent that, the distribution is now queued to be executed on shutdown. With this strategy, only the most recent payload will be distributed in the execution.

This PR also introduces a change to how the distribution meta for the outgoing post works. There's no need for the outgoing post configuration meta to include the network post ID, as it's deterministic. Without it, it's left only with the site URLs. Because of that, it's now only an array of site URLs, and the methods have been renamed from set_config() to set_distribution().

Testing

There should be no functional change, except update_post_meta() should now also trigger an update. Let's test it with the CLI:

  1. Make sure you have a network setup with a hub and 2 nodes (node1 and node2)
  2. In the hub, create a post and distribute to node1:
wp newspack network distribute post <post-id> --sites=https://node1.test
  1. Confirm the post is distributed to node1
  2. Distribute to node2 as well:
wp newspack network distribute post <post-id> --sites=https://node2.test
  1. Confirm the post is distributed to node2
  2. Now update a post meta:
wp post meta update <post-id> custom-meta test
  1. Confirm the post meta gets distributed to both node1 and node2

@miguelpeixe miguelpeixe self-assigned this Dec 13, 2024
@miguelpeixe miguelpeixe requested a review from a team as a code owner December 13, 2024 19:18
@miguelpeixe miguelpeixe requested a review from naxoc December 13, 2024 19:18
Copy link
Member

@naxoc naxoc left a comment

Choose a reason for hiding this comment

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

Tests well! I added a small question/request

* Distribute queued posts.
*/
public static function distribute_queued_posts() {
$post_ids = array_keys( self::$queued_post_updates );
Copy link
Member

Choose a reason for hiding this comment

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

Since we don't check if the values are true or false in the $queued_post_updates array – what do you think about just holding the post ids instead of post_id -> bool in that array? Are there cases we'd be interested in false?

Copy link
Member Author

Choose a reason for hiding this comment

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

I went for a map for efficiency as it's a simple way to ensure uniqueness.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in f9eada2

@miguelpeixe miguelpeixe requested a review from naxoc December 16, 2024 19:53
Copy link
Member

@naxoc naxoc left a comment

Choose a reason for hiding this comment

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

Looks good!
ok

@miguelpeixe miguelpeixe merged commit e76a2dc into trunk Dec 16, 2024
@miguelpeixe miguelpeixe deleted the feat/content-distribution-control-meta branch December 16, 2024 21:53
@github-actions
Copy link

Hey @miguelpeixe, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

matticbot pushed a commit that referenced this pull request Jan 10, 2025
# [2.4.0-alpha.1](v2.3.4...v2.4.0-alpha.1) (2025-01-10)

### Bug Fixes

* **content-distribution:** post insertion hook and additional meta for incoming post event ([#173](#173)) ([48df13c](48df13c))
* load text domain on init hook ([#171](#171)) ([01fb89c](01fb89c))

### Features

* content distribution - experimental ([#168](#168)) ([dc837d8](dc837d8))
* **content-distribution:** add CLI command for distribute post ([#159](#159)) ([7a43b86](7a43b86)), closes [#155](#155) [#156](#156) [#157](#157) [#160](#160) [#165](#165)
* **content-distribution:** canonical url ([#177](#177)) ([5ca60ce](5ca60ce))
* **content-distribution:** capability and admin page ([#176](#176)) ([5285285](5285285))
* **content-distribution:** control distribution meta and prevent multiple dispatches ([#170](#170)) ([e76a2dc](e76a2dc))
* **content-distribution:** editor plugin for distribution ([#167](#167)) ([e10aef4](e10aef4))
* **content-distribution:** handle status changes ([#166](#166)) ([4af5da1](4af5da1))
* **content-distribution:** log incoming post errors ([#182](#182)) ([74c9119](74c9119))
* **content-distribution:** posts column ([#178](#178)) ([8e07640](8e07640))
* **content-distribution:** reserved taxonomies ([#174](#174)) ([a2c54d2](a2c54d2))
* **content-distribution:** sync comment and ping statuses ([#179](#179)) ([90c5425](90c5425))
* **content-distribution:** sync post meta ([#163](#163)) ([353a3d8](353a3d8))
* **event-log:** collapse data ([#180](#180)) ([956219d](956219d))
* limit purchase of a network membership ([#169](#169)) ([deb2683](deb2683))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 2.4.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Jan 20, 2025
# [2.4.0](v2.3.4...v2.4.0) (2025-01-20)

### Bug Fixes

* **content-distribution:** post insertion hook and additional meta for incoming post event ([#173](#173)) ([48df13c](48df13c))
* load text domain on init hook ([#171](#171)) ([01fb89c](01fb89c))

### Features

* content distribution - experimental ([#168](#168)) ([dc837d8](dc837d8))
* **content-distribution:** add CLI command for distribute post ([#159](#159)) ([7a43b86](7a43b86)), closes [#155](#155) [#156](#156) [#157](#157) [#160](#160) [#165](#165)
* **content-distribution:** canonical url ([#177](#177)) ([5ca60ce](5ca60ce))
* **content-distribution:** capability and admin page ([#176](#176)) ([5285285](5285285))
* **content-distribution:** control distribution meta and prevent multiple dispatches ([#170](#170)) ([e76a2dc](e76a2dc))
* **content-distribution:** editor plugin for distribution ([#167](#167)) ([e10aef4](e10aef4))
* **content-distribution:** handle status changes ([#166](#166)) ([4af5da1](4af5da1))
* **content-distribution:** log incoming post errors ([#182](#182)) ([74c9119](74c9119))
* **content-distribution:** posts column ([#178](#178)) ([8e07640](8e07640))
* **content-distribution:** reserved taxonomies ([#174](#174)) ([a2c54d2](a2c54d2))
* **content-distribution:** sync comment and ping statuses ([#179](#179)) ([90c5425](90c5425))
* **content-distribution:** sync post meta ([#163](#163)) ([353a3d8](353a3d8))
* **event-log:** collapse data ([#180](#180)) ([956219d](956219d))
* limit purchase of a network membership ([#169](#169)) ([deb2683](deb2683))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 2.4.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants