-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add functionality to reset page order #129
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ad88c90
Add functionality to reset page order via REST.
ruscoe 65b2d68
Formatting fix.
ruscoe 0ed6d42
Revert "Formatting fix."
ruscoe 6c03c86
Formatting fix.
ruscoe 3094a0b
Replace REST endpoint with admin AJAX solution.
ruscoe f84e170
Add test for resetting page order.
ruscoe b3cf1c7
Update reset page order test to replace cy.wait and to properly check…
ruscoe e33dec6
reset state after tests complete
Sidsector9 bd8a6fc
fix coding standards and replace ajax referer with verify nonce
Sidsector9 c2dc23d
Add wpdb::update() format properties.
ruscoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
describe( 'Test Reset Page Order Change', () => { | ||
it( 'Can reset pages order', () => { | ||
cy.login(); | ||
cy.visit('/wp-admin/edit.php?post_type=page'); | ||
|
||
const firstRow = '.wp-list-table tbody tr:nth-child(1)'; | ||
const secondRow = '.wp-list-table tbody tr:nth-child(2)'; | ||
|
||
// Alias titles as `firstRowText` and `secondRowText` for convenience. | ||
cy.get( firstRow ).find( '.row-title' ).invoke( 'text' ).as( 'firstRowText' ); | ||
cy.get( secondRow ).find( '.row-title' ).invoke( 'text' ).as( 'secondRowText' ); | ||
|
||
// Swap position of `Page 1` with `Page 2`. | ||
cy.get( firstRow ).drag( secondRow ); | ||
|
||
// Verifies if 1st row has title `Page 2`. | ||
cy.get( firstRow ).find( '.row-title' ).invoke( 'text' ).then( function( text ) { | ||
expect( text ).to.eq( this.secondRowText ); | ||
} ); | ||
|
||
// Verifies if 2nd row has title `Page 1`. | ||
cy.get( secondRow ).find( '.row-title' ).invoke( 'text' ).then( function( text ) { | ||
expect( text ).to.eq( this.firstRowText ); | ||
} ); | ||
|
||
// Now reset the page order and verify original values are back. | ||
cy.get( '#contextual-help-link' ).click(); | ||
cy.get( '#tab-link-simple_page_ordering_help_tab' ).click(); | ||
cy.get( '#simple-page-ordering-reset' ).click(); | ||
cy.on( 'window:confirm', () => true ); | ||
|
||
// Perform a reload as Cypress won't after window:confirm. | ||
cy.reload(); | ||
|
||
// Verifies if 1st row has title `Page 1`. | ||
cy.get( firstRow ).find( '.row-title' ).invoke( 'text' ).then( function( text ) { | ||
expect( text ).to.eq( this.firstRowText ); | ||
} ); | ||
|
||
// Verifies if 2nd row has title `Page 2`. | ||
cy.get( secondRow ).find( '.row-title' ).invoke( 'text' ).then( function( text ) { | ||
expect( text ).to.eq( this.secondRowText ); | ||
} ); | ||
} ); | ||
} ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dkotter This PR works well. The only area that I am concerned about is the performance impact due to this line.
Would this be an issue for an extremely large database? If so, should we look into performing the updates in batches?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the code
wpdb::update
runs, seems like the final query will be something like:I think that should scale fairly well and we won't need to worry about doing any sort of batching here. That said, @ruscoe if you'd be able to do some quick testing on various sizes to see the performance impact, that would help us be more confident about merging this in. Something like profiling this code when run on a site that has 10 pages, 100 pages and 1000 pages, that would be helpful.
In addition, I think best practice here is to utilize the format properties of the
update
method. Something likeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dkotter No problem at all! I profiled by measuring execution time.
Just to show my process, first I used a quick shell script to create pages:
Then used the following to test:
Taking the average of five test runs each:
10 posts: 0.0041 microseconds
100 posts: 0.0042 microseconds
1000 posts: 0.0116 microseconds
5000 posts: 0.0299 microseconds
How does that look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ruscoe! Definitely see an increase in time as the number of posts increase but the overall amount of time is so low that this doesn't seem like it will cause any problems. This looks good to go on my end