Repository navigation
fix(rsvp): ignore an older guest count save - #2650
faisalahammad wants to merge 4 commits into
Conversation
- Send a page ID and a save order with each guest count save. - Skip a save in the RSVP endpoint when a same or newer order from the same page is already stored, and return the stored RSVP. - Keep the order of the last five pages in comment meta, so tabs do not block each other. - Add PHP and JS tests and a changelog entry. Why: a save sent on page leave can reach the server after an older save that is still on its way, and the older count then wins. Fixes GatherPress#2641
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test Coverage Report✅ All coverage checks passed! ✅ PHP Coverage✅ JavaScript CoverageThis comment is automatically updated on each push. |
- Rename find_newer_save() to save_in_order(), which now does the save too. - Drop the ternary from update_rsvp() and the unused State import. Why: the ternary pushed the NPath complexity of update_rsvp() over the PHP Mess Detector limit.
mattcowan
left a comment
There was a problem hiding this comment.
The fix works as described. One inline comment, the server takes whatever the browser sends for the two new fields. A bad value causes a PHP warning or puts a very long string into the database. Declaring the fields lets WordPress refuse bad values before the code runs.
…older-guest-count-save
- Declare save_page (string, max 64) and save_order (integer, min 1) in the rsvp route args so WordPress refuses bad values with a 400. - Add a dispatch test for refused and accepted values. Addresses PR feedback. Refs GatherPress#2650
faisalahammad
left a comment
There was a problem hiding this comment.
@mattcowan thanks for the review. I added the route args you asked for in 4d96326, with a test that sends requests through the route. I also merged the latest develop. Can you take another look when you have time?
Preview changes with PlaygroundCustomize PR PlaygroundTo customize the Playground preview for this specific PR, create a file at:
The override is merged into the generated blueprint and can be used to:
Example: {
"$schema": "https://gatherpress.org/playground-preview/pr-override-schema.json",
"landingPage": "/wp-admin/edit.php?post_type=gatherpress_venue",
"siteOptions": {
"show_on_front": "page"
},
"features": {
"networking": true
},
"prependSteps": [
{
"step": "installPlugin",
"pluginData": {
"resource": "wordpress.org/plugins",
"slug": "simple-location"
},
"options": {
"activate": true
}
}
],
"appendSteps": [
{
"step": "runPHP",
"code": ""
}
]
}Go to Playground PR preview customization for more details. You can preview the recent changes for PR#2650 with the following PHP versions: PHP Version 8.4PHP Version 8.2PHP Version 8.1Download Made with 💙 from GatherPress & a little bit of WordPress Playground. Changes will not persist between sessions. |
Fixes #2641
Proposed changes:
save_pageID (made once per page load) and asave_ordernumber that goes up with each change.POST gatherpress/v1/rsvpchecks the order stored on the RSVP comment (gatherpress_rsvp_save_ordermeta). If the same page already saved a same or higher order, the request skips the save and returns the stored RSVP. Otherwise it stores the new order and saves as before.Before, a save sent on page leave (with
keepalive) could reach the server after an older save that was still on its way. The older guest count then won.One known limit: two requests from the same page that run in PHP at the exact same moment can still race. The window is milliseconds, and closing it would need a lock around the check and the save.
Other information:
AI assistance
Testing instructions:
Setup: create a future event with Maximum Number of Guests set to 5 or more. Log in, open the event on the front end, and RSVP as Attending. Open dev tools, Network tab, filtered on
rsvp.Test 1: normal save
rsvprequest is sent withguests: 3,save_pageandsave_order.Test 2: older save arriving last is ignored
Test 3: other tabs are not blocked
Test 4: other actions unchanged
save_pageorsave_order.Credit (for release notes)
My WordPress.org username: faisal03
Changelog entry
The entry is committed in
.github/changelog/2641-guest-count-save-order.Changelog Entry Details
Significance
Type
Message
Keep the newest guest count when an older save reaches the server after it, such as when the page is left during a save.