[buddypress-trac] [BuddyPress Trac] #7996: bp_email_set_default_tokens() (or some part of email sending) should switch to root blog

buddypress-trac noreply at wordpress.org
Mon Oct 29 19:07:49 UTC 2018


#7996: bp_email_set_default_tokens() (or some part of email sending) should switch
to root blog
--------------------------+--------------------
 Reporter:  boonebgorges  |      Owner:  DJPaul
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  4.0
Component:  Emails        |    Version:
 Severity:  major         |   Keywords:
--------------------------+--------------------
 In investigating performance problems on a client site, I've traced a
 couple of apparently disparate issues back to what seems to be a common
 source. Briefly, if you trigger the sending of an email, via
 bp_send_email(), from a non-root site on a Multisite network, it can cause
 a cascade of problems.

 The crux of the issue in the cases I've seen seems to be
 `bp_email_set_default_tokens()`. Most of the email API is pretty careful
 to be self-contained, but there are a few places in
 `bp_email_set_default_tokens()` where the function calls are context-
 specific:
 - `home_url()` will always reference the current site
 - `get_post_meta()`
 https://buddypress.trac.wordpress.org/browser/tags/3.2.0/src/bp-core/bp-
 core-filters.php#L1085 will fetch the post from the current site rather
 than the root site (note that `$email->get_post_object()` doesn't have the
 same problem, since `set_post_object()` is set inside of
 `switch_to_blog()` in `bp_send_email()`

 The latter case is especially problematic, especially for plugins that
 intervene in the post/postmeta fetching process. The cases that are
 causing problems for my client, for example, are linked to a plugin that
 hooks to `get_post_metadata()` but gets an ID for a post on the root blog,
 which it can never find, so it ends up running thousands of database
 queries.

 A couple different strategies for fixing this, ranging from the most to
 the least targeted:

 1. Change the `home_url()` and `get_post_meta()` calls to method wrappers.
 Something like: `bp_get_root_domain()`, and a new
 `$email->get_preheader()` or something like that.

 2. Perform all of the internal logic of `bp_email_set_default_tokens()`
 inside a `switch_to_blog()` statement.

 3. Perform all of the internal logic of `bp_send_email()` inside a
 `switch_to_blog()` statement.

 Strategy 1 is architecturally the nicest, but it also assumes that I've
 correctly identified all of the context-sensitive links in the chain.
 Strategy 2 and 3 move progressively more of the email-sending routine into
 a switched-blog context.

 I'd value thoughts from @DJPaul, as well as from @r-a-y, who knows about
 the details of the specific client project.

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7996>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list