Display metadata in the table#1462
Conversation
6e4ddbe to
b6b753f
Compare
|
@kasparsd any chance of getting this merged? I've rebased this on the current release, it still works. |
|
Nice to have an option like "Retrieve meta data to display" in order to not overload DB when it is not needed. |
|
@akirk thanks for the PR. I agree that it would be best to make this feature optional. Do you have the capacity to add a setting that enables it? |
52e6d2d to
cec619a
Compare
|
Hi @akirk, are you still interested in landing this? The metadata display feature is useful and your recent rebase suggests you might be. To move forward, two things:
Happy to help with either or take it over if you'd prefer to hand it off. AI-assisted code reviewFindings on the diff between this PR's HEAD and current Blockers1.
2.
Use 3. public function get_meta( $meta_key = '', $single = false ) {
$meta = get_metadata( 'record', $this->ID, $meta_key, $single );
if ( '' === $meta_key || ! empty( $meta ) ) {
return '' === $meta_key ? self::normalize_meta( $meta ) : $meta;
}
$all_meta = self::normalize_meta( get_metadata( 'record', $this->ID ) );
if ( ! array_key_exists( $meta_key, $all_meta ) ) {
return $single ? '' : array();
}
return $single ? $all_meta[ $meta_key ] : array( $all_meta[ $meta_key ] );
}Trace
WP's Also: the fall-through executes a second SQL query on every key miss. On a list-table render of 50 rows, that's an extra 50 queries when none of the records have the requested key. Simplest fix: drop the magic. Keep Warnings4. Before this PR, nested-array meta was written with sub-keys discarded. After this PR, the same input writes Both shapes coexist in
Where this does not matter on current core: the list table's own Summary/User columns, connectors, exporters, and alerts do not read Recommendation: don't ship a migration; document the split. Old records are still useful (the values are searchable strings even without sub-keys), so a lossy-delete migration removes data unnecessarily. Position-based remapping is fragile (the old write loop's empty-value filter shifts positions per-record) and shouldn't be attempted. A changelog note plus a paragraph in the MCP ability docs is enough: "Records logged before X.Y.Z return 5. Before:
The unwrap arguably matches what most callers expected anyway ( 6. if ( is_array( $value ) ) {
$value = array_map( 'maybe_unserialize', $value );
if ( 1 === count( $value ) ) {
return reset( $value );
}
return $value;
}This is what produces the unwrap in finding 5. It diverges from 7. - FROM $wpdb->stream
- {$join}
- WHERE 1=1 {$where}";
+ FROM $wpdb->stream
+ WHERE 1=1 {$where}";
8. The second SQL uses
9. if ( $with_meta ) {
if ( ! empty( $fields ) && ! in_array( 'ID', $fields, true ) ) {
$selects[] = "$wpdb->stream.ID AS record_id";
}
}Cleaner: if 10.
Nits11. 12. 13. 14. 15. Test coverage: please add cases for the legacy multi-row format (insert old shape via raw SQL, read via |
|
Yes! Thanks for that review. I didn't have enough time to test it thoroughly enough after my changes, so I hadn't continued the conversation yet. |
Fixes #947.
The metadata that can be stored along side records is burried in the
stream_metatable. This make the data accessible in the table.Checklist
contributing.md).I have run the code. I am unable to run the local development environment on a recent Macbook Pro. Maybe the environment should be updated in a separate PR.
Thus, I have also not been able to check the unit tests yet.
Release Changelog
Release Checklist
masterbranch.readme.txt.stream.php.Stable taginreadme.txt.classes/class-plugin.php.Change
[ ]to[x]to mark the items as done.