Opened 12 years ago
Closed 11 years ago
#4551 closed enhancement (fixed)
Use WP's metadata API
Reported by: | sbrajesh | Owned by: | |
---|---|---|---|
Milestone: | 2.0 | Priority: | normal |
Severity: | major | Version: | 1.2 |
Component: | Core | Keywords: | |
Cc: | sbrajesh |
Description
Hi,
I am working on some code for a friend of mine and I need to filter on the total member count.
As these values are stored in the group meta, we need to filter on groups_get_groupmeta value.
Currently groups_get_groupmeta does not allow filtering. Since BuddyPress is following the footprints of WordPress, I believe we should have this functionality in BuddyPress. WordPress metadata api does provide early filtering.
If the devs approve this, I will put a patch quickly.
Attachments (5)
Change History (36)
#2
@
12 years ago
Thank You Boone.
I will be more than happy to do that :)
Will be putting the patch by tomorrow :)
#3
@
12 years ago
- Component changed from Groups to Core
- Keywords has-patch added; needs-patch removed
Hi,
Here is a patch attached which is modeled after wordpress meta api.
This patch introduces a meta api for BuddyPress. Any plugin can leverage the api to query for meta data.
Also, It includes BP_Meta_Query class which is a derivative of Wp_Meta_Query class and works exactly in the same manner.
This patch is against r6465 on the bp 1.6 branch. Please check and let us improve it. Is it acceptable to have this short of api ? Introducing the api does reduces the code for different component meta functions.
Please note, this patch includes updates for activity,blog,group meta using the new api but not for xprofile meta as xprofile metas have a little bit different organization strategy.
Looking forward to hear the feedbacks.
Please let me know if we should have it against the 1.7 trunk?
#4
@
12 years ago
In general terms, patches for new features are best against Trunk because I think it is unlikely we will add a major feature or API change into a 1.6.x point release; we've been guilty of this in the past, but we've learnt that lesson :)
Looking forward to checking out the patch once I get some time. Quick question. Are we unable to use WP_Meta_Query directly? I see the patch only implements one method.
#5
@
12 years ago
Hi Paul,
Thank you for taking a look and asking.
The problem with WP_Meta_Query is it uses the function _get_meta_table in the method get_sql which does not allow filtering, so we could not pass our custom table names there. Otherwise, we can use rest of its code.
The current patch introduces _bp_get_meta_table which allows filtering. If it is possible, and we can get a patch for it in wp core, we may not even need the meta data api and just use wordpress's built in meta data api. The only issue is the use of _get_meta_table in those functions which restricts us from using it.
I will be putting a patch for 1.7 trunk too. I put the patch for bp 1.6 trunk as my Friend Hans needed it for Bp 1.6 :)
#6
@
12 years ago
- Keywords needs-refresh added
- Milestone changed from Awaiting Review to Future Release
Has a patch, but needs to be reviewed and refreshed for trunk. Moving to future release.
#9
@
12 years ago
- Milestone changed from 1.8 to Future Release
- Severity changed from minor to normal
- Summary changed from groups_get_groupmeta should allow filtering the value to Use WP's metadata API
- Version changed from 1.6.1 to 1.2
I like the idea behind the patch, but I don't like how we're duplicating the entire WP meta API to accomplish this because we are unable to override some variables.
sbrajesh is correct that we should pass a patch upstream to filter _get_meta_table()
and to the various hardcoded variables in the *_metadata() functions like this.
This would prevent so much code duplication. The other issue I can see is maintaining backpat cache with our own cache keys (if that is even necessary).
I'll post a patch upstream and will update this ticket, but until then I'm pushing this back to Future Release.
#10
@
11 years ago
@r-a-y, @sbrajesh
Was a ticket ever made for this on the WP core trac? I'm a bit unclear as to what parameters we'd need filterable (beyond the linked example on line 114), but happy to do it if someone can give me a hand.
#13
@
11 years ago
- Keywords needs-testing 2nd-opinion added; needs-refresh removed
- Milestone changed from Future Release to 2.0
4551.patch is a proof-of-concept for groupmeta. The strategy will apply directly to activitymeta and forummeta.
Technical notes:
- I have preserved all the quirks of the existing meta functions (like returning an unstructured array of values when passing a null meta key to groups_get_groupmeta()). My first goal is to get it working exactly like the existing functions, then we can worry about improvements.
- To make WP see the table name, I put it into the $wpdb global, as DJPaul suggests above.
- WP's functions hardcode
meta_id
into their SQL queries. We useid
for our primary columns. To get around this, I introduce a littlestr_replace()
filter (bp_filter_metaid_column_name()) that gets added to 'query' just before we run the core function, and removed right after. This is the least elegant part of the patch, but it works well. - The functions now have pretty complete unit test coverage. 4551.patch passes the tests.
Would like another set of eyes on this before moving on to the other components.
#14
@
11 years ago
This is great, Boone. Really nicely done.
4551.02.patch expands on Boone's concept above, but goes further into creating an API for registering metadata tables in the BP_Component
class.
Indirectly as a result of the above changes, I've introduced a BP_Component
method to help handle and store global table data to match the metadata table registration process.
This ticket was mentioned in IRC in #buddypress-dev by jjj. View the logs.
11 years ago
#16
@
11 years ago
- Keywords needs-unit-tests commit added; needs-testing 2nd-opinion removed
I'm comfortable with this getting committed into trunk.
#19
@
11 years ago
- Keywords commit removed
Thanks, johnjamesjacoby.
4551.4.patch is the bp-activity portion of your previous patch. It's broken a number of the existing unit tests, and in addition we should have complete unit test coverage of the functions before committing. I can try to get on this in the next few days, but I'm posting .4 here for time being to keep track of it (and in case anyone gets to it first).
In the meantime, certain group cache-priming needs to be cleaned up.
This ticket was mentioned in IRC in #buddypress-dev by boonebgorges. View the logs.
11 years ago
#31
@
11 years ago
- Keywords has-patch needs-unit-tests removed
- Resolution set to fixed
- Severity changed from normal to major
- Status changed from new to closed
All of our custom meta functions have now been migrated. Hooray!
A big bonus is that we now have decent test coverage for these functions. Double hooray!
A review of metadata caching is now needed, especially for those components where it was never fully implemented in the first place (xprofile and blogs). I've opened a new ticket for those who would like to follow along: #5398
Marking as resolved.
I'm OK with this. Can you please make sure that our filters work just like WP's (same syntax and location)? Also, if you could patch our other meta functions (activity, xprofile, blog), that would be great :)