Make WordPress Core

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#30577 closed enhancement (maybelater)

Allow plugins to bypass wp_options when saving transients

Reported by: mgibbs189's profile mgibbs189 Owned by: rmccue's profile rmccue
Milestone: Priority: normal
Severity: normal Version: 2.8
Component: Options, Meta APIs Keywords:
Focuses: Cc:

Description

In set_transient(), the only way to prevent transients from using the wp_options table is by using a custom object-cache.php drop-in.

This isn't consistent with get_transient(), which does have a filter to short-circuit transient retrieval (pre_transient_*).

This patch allows plugins to bypass the options table when saving transients.

Full disclosure: I'm writing a plugin to store transients in a separate table, instead of cluttering wp_options. Reference: https://github.com/mgibbs189/better-transients

Attachments (4)

option.php.patch (633 bytes) - added by mgibbs189 9 years ago.
option.php.2.patch (636 bytes) - added by mgibbs189 9 years ago.
option.php.3.patch (902 bytes) - added by mgibbs189 9 years ago.
30577-bypass-options-set-transient.4.diff (2.7 KB) - added by jipmoors 9 years ago.
Moved the filter after external cache check and renamed to reflect better what it does

Download all attachments as: .zip

Change History (27)

#1 @mgibbs189
9 years ago

  • Keywords has-patch dev-feedback added

#2 @rmccue
9 years ago

+1 on the concept, if only to match the pre_update_option_{$option} and pre_update_option filters. (Although I think the concept of moving transients to another table is flawed, there are probably other valid use cases regardless.)

That said, the filter should definitely be called pre_set_transient. Also, the above patch is missing the close brace for the if, which is a syntax error.

#3 @mgibbs189
9 years ago

rmccue, I've updated the patch based on your feedback. Thanks.

#4 @rmccue
9 years ago

  • Keywords dev-feedback removed

Also, just to beat DrewAPicture to the punch, needs hook documentation as well.

#5 @mgibbs189
9 years ago

rmccue All set.

#6 @rmccue
9 years ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 4.1

Loving it. Let's see if we can sneak this bad boy into 4.1.

#7 @johnbillion
9 years ago

  • Keywords 4.2-early added
  • Milestone changed from 4.1 to Future Release

#8 @johnbillion
9 years ago

  • Version changed from trunk to 2.8

#9 @iseulde
9 years ago

  • Milestone changed from Future Release to 4.2

has-patch 4.2-early so moving to 4.2.

#10 follow-up: @mbrandys
9 years ago

I think that bypass conditional should be placed before wp_using_ext_object_cache one to match how it it's done in get_transient as it still forces saving data in external data storage when someone uses object-cache.php drop-in.

This ticket was mentioned in Slack in #core by drew. View the logs.


9 years ago

#12 @DrewAPicture
9 years ago

The latest patch still applies. I'd love to have a lead weigh in here, maybe @helen, @nacin, or @markjaquith.

#13 @DrewAPicture
9 years ago

  • Milestone changed from 4.2 to Future Release

Pushing to future release unless a committer would like to pull it back, for the 4.2 release at least.

#14 in reply to: ↑ 10 @nacin
9 years ago

Replying to mbrandys:

I think that bypass conditional should be placed before wp_using_ext_object_cache one to match how it it's done in get_transient as it still forces saving data in external data storage when someone uses object-cache.php drop-in.

I agree with this assessment. Thank you @mgibbs189 for your "full disclosure" — this is really helpful to ascertain your use case, and is always something we'll ask for. It also explains why you wanted to do this *after* wp_using_ext_object_cache(). But it shouldn't be to be more generally useful. You however can use wp_using_ext_object_cache() in your callback, so your use case is fine.

Also, I'm not sure I like the filter name. When we have a specific action or filter like "filter_name_$name" combined with a generic one (i.e. "filter_name"), they should do the same thing and function the same way. pre_site_transient_$transient already exists. pre_site_transient should not exist and then do different functionality.

Any proposed changes here should be mirrored to set_site_transient().

I *do* like the idea, it just needs some more work. Also, I bet there's a way to do this by filtering in the options API, so there's at least a hacky workaround.

#15 @mgibbs189
9 years ago

@nacin @mbrandys thanks for the feedback.

I think it'd be fine to move the hook above wp_using_ext_object_cache() - I had moved it *after* wp_using_ext_object_cache() because I figured external cache would need to take precedence. E.g. with the way it's currently set up, external cache is given a chance to run before the bypass filter.

Also, any suggestions for the filter name? Maybe something like bypass_set_transient?

#16 @mgibbs189
9 years ago

  • Keywords dev-feedback added

#17 @jipmoors
9 years ago

First of all, could you make the diff file from the trunk next time? Perhaps adding the ticket number in front would be a good addition for clearity.

I suggest to move the filter to after the wp_using_ext_object_cache() so hooks won't get the wrong idea that they can manipulate stuff that is ignored later on.

On the naming of the filter, I think it would be adding to the clearity if it represented more of what it's doing, 'allow_set_transient_to_options'.

Setting 'result' to true does not reflect what the code is doing, I can imagine that not calling the actions on a success could result in unwanted behaviour but it sounds like the proper thing to do when you bypass saving the value. Would appreciate 2nd opinion on this.

@jipmoors
9 years ago

Moved the filter after external cache check and renamed to reflect better what it does

#18 @obenland
8 years ago

  • Owner set to rmccue
  • Status changed from new to assigned

#19 @obenland
8 years ago

  • Keywords 4.2-early removed
  • Milestone changed from Future Release to 4.3

#20 @obenland
8 years ago

  • Keywords changed from has-patch, commit, dev-feedback to has-patch commit dev-feedback

@rmccue, beta is two weeks away. I'm inclined to punt unless you can get it ready soon.

Last edited 8 years ago by obenland (previous) (diff)

#21 @obenland
8 years ago

  • Keywords commit removed
  • Milestone changed from 4.3 to Future Release

#22 @mgibbs189
8 years ago

  • Keywords has-patch dev-feedback removed
  • Resolution set to maybelater
  • Status changed from assigned to closed

Closing. Looks like this one isn't gonna happen.

#23 @netweb
8 years ago

  • Milestone Future Release deleted

Closed tickets shouldn't have a milestone so I've removed the milestone.

Pinging @rmccue, are you still interested in this? If so reopen and milestone etc

Note: See TracTickets for help on using tickets.