Database setup / DBTable improvements
-
Currently plugin performs
SHOW TABLES LIKE ...on every page load, which is a slow and inefficient compared to simple SELECT query by callingcreateTable()method fromcreateDBTables()inDBTableclass.The better approach would be to introduce a database versioning system. Here is a simple example: https://gist.github.com/kurtpayne/2151282. You could probably implement it inside
createDBTables()method leaving your existingcreateTable()method as is.
Now, on each page request plugin will still call get_option(‘your_db_version_str’) and that’s fine because we can give instructions to autoload this option when user activates the plugin, and set the autoload flag to ‘no’ when plugin is deactivated. Here is WordPress blog post explaining option function improvements with an example: https://make.wordpress.org/core/2023/10/17/new-option-functions-in-6-4/#new-functions-to-set-option-autoload-values
PS: if you intend to support older WordPress versions, you will have to wrapwp_set_options_autoload()or any other new functions infunction_exists().
The topic ‘Database setup / DBTable improvements’ is closed to new replies.