Skip to content

Add support for --order, --orderby flags in wp db size command#226

Merged
danielbachhuber merged 11 commits intowp-cli:masterfrom
kjohnson:feature/order-tables-225
Sep 29, 2022
Merged

Add support for --order, --orderby flags in wp db size command#226
danielbachhuber merged 11 commits intowp-cli:masterfrom
kjohnson:feature/order-tables-225

Conversation

@kjohnson
Copy link
Contributor

@kjohnson kjohnson commented Sep 15, 2022

Resolves #225 by adding support for the --order and --orderby flags to the wp db size command when displaying table sizes.

@kjohnson kjohnson changed the title Add support for order, orderby in db size command Add support for order, orderby flags in wp db size command Sep 15, 2022
@kjohnson kjohnson changed the title Add support for order, orderby flags in wp db size command Add support for --order, --orderby flags in wp db size command Sep 15, 2022
@kjohnson kjohnson marked this pull request as ready for review September 15, 2022 14:03
@kjohnson kjohnson requested a review from a team as a code owner September 15, 2022 14:03
Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

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

Great start, @kjohnson !

Overall, it looks really good. Left a few comments with things to be cleaned up. Once they're done, we can 🚢

$rows[] = [
'Name' => DB_NAME,
'Size' => strtoupper( $db_bytes ) . $default_unit,
'_Bytes' => strtoupper( $db_bytes ),
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason we need to add an underscore to _Bytes? I think it's fine to include in the output...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fields are configured above that line to only output Name and Size, so I added an _ to the Bytes temporary key as a convention for visibility. It doesn't change the code either way, so it can be easily removed if you'd like.

Copy link
Member

Choose a reason for hiding this comment

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

Cool, let's go ahead and remove the underscore. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved by 8ba0f6a.

@danielbachhuber danielbachhuber self-requested a review September 20, 2022 21:33
Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

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

Nice work on this, @kjohnson !

@danielbachhuber
Copy link
Member

@kjohnson Any ideas why that test is failing? ^

@kjohnson
Copy link
Contributor Author

@danielbachhuber it looks like the extra posts/pages aren't getting generated. In that test the wp_posts table should be significantly larger, but the listed size is the original size of the table as if the posts where not generated.

@kjohnson
Copy link
Contributor Author

@danielbachhuber intermittently it looks like the posts are not being generated. When I run wp post list --post_type=page --format=count is sometimes comes back as 1.

    And I run `wp post generate --post_type=page --post_status=draft --count=300`
    And I run `wp post list --post_type=page --format=count`
    Then STDOUT should be:
    """
    300
    """

@kjohnson
Copy link
Contributor Author

I've added and removed wp site empty --yes during local testing as I tried to figure out how to test this. I just added it back which might help with the above failed tests.

@danielbachhuber
Copy link
Member

I've added and removed wp site empty --yes during local testing as I tried to figure out how to test this. I just added it back which might help with the above failed tests.

So weird! Now we're getting another odd failure:

image

Not sure what the issue is 😕 I'll debug further when I have some more time.

@kjohnson
Copy link
Contributor Author

Funny that the DB Command is having database related issues during testing. 😅

Are we able to re-run tests on master to confirm that this issue is related to this PR?

@danielbachhuber
Copy link
Member

Are we able to re-run tests on master to confirm that this issue is related to this PR?

Looks like there's a WordPress trunk failure on master:

image

@danielbachhuber
Copy link
Member

Looks like there's a WordPress trunk failure on master:

Here's the issue: https://core.trac.wordpress.org/ticket/56617

@kjohnson
Copy link
Contributor Author

Ok, yeah, looks like a day earlier and this would have been in the clear 😅

Nice to see that there is a patch ready to go.

@danielbachhuber
Copy link
Member

These are pretty annoying test failures!

I spent some time debugging again today. As far as I can tell, there might be a couple of issues:

  1. The table size is cached in information_schema.TABLES. Sometimes the cache updates, sometimes it doesn't. This might be a long-term issue. I wasn't able to get FLUSH TABLES or ANALYZE TABLE %s to reliably update he cache.
  2. Empty table sizes may actually vary based on storage engine.

I've manually verified your new arguments worked, and marked the tests @broken for now: 4f331be

Appreciate your efforts on this!

@danielbachhuber danielbachhuber merged commit 8965e56 into wp-cli:master Sep 29, 2022
danielbachhuber added a commit that referenced this pull request Nov 18, 2022
…226)

Co-authored-by: Daniel Bachhuber <daniel@bachhuber.co>
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.

Add --order=<order> and --orderby=<orderby> arguments to wp db size

3 participants