Git Product home page Git Product logo

Comments (9)

claytoncollie avatar claytoncollie commented on July 25, 2024 3

I like the pre_option way of doing it b/c you can see it easier in the codebase. People understand how it relates to WordPress by using a core function. By doing an array compare, you are introducing custom logic that might be foreign to outsiders. You are also introducing a storage place for the temp version. Where does that get stored? Can it be lost or corrupted? How can you delete it when needed?

from intervention.

pacotole avatar pacotole commented on July 25, 2024 2

Yes, I have the same question.

In principle, the pre_option_{$option} seems better, which bypass all the logic of the get_option function and returns the desired value. The downside is that you lose all settings when exporting or if you need to disable Intervention.

The update_option store your config on DB and solves previous downside. It should really only update on the first page load because update_option compares the values and if they are equal, they are not updated and there is no database hit. But there is a problem with numeric values: they are strictly compared with DB (string) value and always return false so forces an DB update on every page load.

I have actually added a filter that prevents this problem on this branch (I'm not sure if it's the best file to add this code) and stops with DB updates on every load.

I am open to suggestions to modify it or to make a pull request ๐Ÿ™‚

from intervention.

nlemoine avatar nlemoine commented on July 25, 2024 1

I'm all with @claytoncollie here. pre_option seems the better option IMO. I think it's fair to assume that using the plugin is short cutting options handling and obviously deactivating it will result in falling back to default, unchanged, database options. Describing clearly that behavior in the readme should be enough.

Maybe the best option would be to introduce a way to manually set options to DB if needed?

from intervention.

darrenjacoby avatar darrenjacoby commented on July 25, 2024

Hey @claytoncollie,

I'm open to the suggestion of changing to pre_option, initially I wanted to update the DB value, but perhaps that's not necessary. What's your thoughts? I'm trying to preempt any downsides to using pre_option for users.

from intervention.

claytoncollie avatar claytoncollie commented on July 25, 2024

I have not used this package yet so this is only thinking out loud. If you enabled all options in your config array then went to random pages in the wp-admin with Query Monitor turned on, you could see how many queries are being generated on each page load. My thought is that you are performing 2 database actions for each page load for each option. First to make the update_option call, then the standard get_option call afterward. With pre_option_ it might be able to get rid of both. The only problem is that your database is not a source of truth anymore when you export for some reason. Pushing and pulling between environments would be fine if the codebase is version controlled, but your DB could potentially be "out of date" to what your config is.

My original question was to see if any thought was given to it and if using update_option was a conscious decision. Sounds like it was when you first started the project. I don't know the project well enough if you can give the option to filter the option or update the database.

from intervention.

darrenjacoby avatar darrenjacoby commented on July 25, 2024

Hey @claytoncollie,

Let me give it some more thought and do a little prototyping, perhaps an approach that uses both, only updating the DB at certain intervals, or on the dashboard/settings pages, or a version of that, and pre_option otherwise.

Edit: Thinking about it more, I don't think it's a deal breaker if the DB actually doesn't update, the plugin should always be enabled to pass across those options in my opinion. I'll keep this issue open so that others can also weigh in.

from intervention.

darrenjacoby avatar darrenjacoby commented on July 25, 2024

Hey @pacotole,

This looks great, thank you! I think having it in that file is perfect.

I'll do some prototyping with update_option and pre_option.

Another line of thought could be comparing the application config with a temp version, and if there are changes to the application config, updating the DB and the temp version. Then we wouldn't even really need pre_option, while also removing unnecessary requests/guesswork. Thoughts?

Edit: PR request for the above would be great, I'll prob change array_map to an Laravel collection to match the rest of the codebase, but I can change that up!

from intervention.

darrenjacoby avatar darrenjacoby commented on July 25, 2024

Yea, fair points that I agree with, thanks for thinking that through. Alright, so letโ€™s go with pre_option and an occasional DB request! Iโ€™ll take a look at getting it changed soon.

from intervention.

darrenjacoby avatar darrenjacoby commented on July 25, 2024

This has been addressed in d5ee64 with a new internal Options API, which now uses pre_option.

from intervention.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.