#2959 closed task (blessed) (fixed)
Favorites & Subscriptions Roadmap
Reported by: | johnjamesjacoby | Owned by: | |
---|---|---|---|
Milestone: | 2.6 | Priority: | high |
Severity: | major | Version: | 2.0 |
Component: | API - Subscriptions | Keywords: | needs-patch needs-testing |
Cc: | jmdodd@… |
Description (last modified by )
With the introduction (and subsequent reinvention) of the per-forum moderator feature for bbPress 2.6, there is opportunity to use this new set of APIs to improve Subscriptions & Favorites.
One problem is favorites & subscriptions are currently stored per-user, serialized in wp_usermeta
. The reasoning for this originally, was that this meta-data was specific enough to the user that it was okay to keep there.
Another problem is querying for which user IDs are subscribed to which forums or topics requires a specific FIND_IN_SET
MySQL flag, which ends up transversing those serialized wp_usermeta
values looking for post IDs.
This logic fails hard with Notifications: when replying to a topic or creating a new topic in a forum, querying for all subscribed users to notify them via email, is a query that does not perform very well when there are millions of rows in wp_usermeta
.
So we have two problems that are very uncharacteristic of bbPress's heritage: performance, simplicity.
How to *properly* store these connections inside of WordPress was less obvious in 2010 than it is today.
Using the new per-forum moderator approach as the foundation, the future of Subscriptions & Favorites should be storing a per-feature meta-key in postmeta
with a meta-value of the $user_id
, like:
add_post_meta( $post_id, '_bbp_subscriber_id', $user_id );
Notice we use add_post_meta()
which allows for duplicate meta-keys for the same post (vs. update_post_meta()
which will update existing data.)
This allows for easy two-way querying:
Get subscribers for a topic:
get_post_meta( $post_id, '_bbp_subscriber_id', false );
Get subscribed topics for a user:
$topics = get_posts( array( 'post_type' => bbp_get_topic_post_type(), 'meta_key' => '_bbp_subscriber_id', 'meta_type' => 'NUMERIC', 'meta_value' => $user_id, 'numberposts' => -1 ) );
Notice that using this approach, we're able to use built in core functions in both directions. Further optimization can be achieved by writing some type of "meta-only" query class that does not require the joining of the wp_posts
table, though I believe that is outside of the scope of this first pass.
How do we codify this quickly:
- Abstract the way user IDs are added to meta-data tables out from per-forum moderators. This should internally allow for hot-wapping the object-type from Posts to Taxonomy Terms.
- Update the per-forum moderator functions to use this new abstraction
- Update the Subscription helper & wrapper functions to use this
- Update the Favorites helper & wrapper functions to use this
- Build an upgrader to migrate existing
wp_usermeta
data into the appropriate meta-data tables (posts for now, taxonomy term meta for forums later)
Attachments (3)
Change History (40)
#4
@
9 years ago
I'll add that a custom pointer table to connect user IDs to post IDs with a "relationship_type" would be the ideal solution. Unfortunately, it's much more work to build this out, and should we ever need to get to this point, it's another simple data migration to pull this out from wp_postmeta
and into wp_user_relationships
or whatever.
@
9 years ago
Creates meta functions and corresponding unit test coverage; updates moderators, subscriptions, and favorites.
#6
@
8 years ago
Related: #meta1980 Forums: Subscribe/unsubscribe actions not functioning
#17
@
8 years ago
Quick note: the tools introduced in r6174 should probably get switched to faster INSERT INTO
queries like we've done for the others. I more just wanted to get a first pass in so we could see the manual process first.
If anyone wants to make a second pass at improving these, please make it so.
In my opinion, this should be completed before (or as part of) the mass data migration of WordPress.org's bigger forum installation. As usual, we can (and I believe should) use bbPress.org & BuddyPress.org as our training wheels to get this deployed there first.