`register_uninstall_hook()` called on every page load results into multiple unnecessary database queries #73

Closed
bjork opened this Issue Dec 26, 2016 · 1 comment

Projects

None yet

2 participants

@bjork
Contributor
bjork commented Dec 26, 2016

In the end of the main plugin file, autoptimize.php, register_uninstall_hook() is called every time the plugin loads. This results into two SELECTs and one UPDATE on every page load.

While the queries are not very expensive they are unnecessary. Eliminating the queries halves the database query time on my blog from 40 milliseconds to 20 ms.

The easiest way to fix this would be to wrap the call to register_uninstall_hook() like this:

function autoptimize_activate(){
    register_uninstall_hook( __FILE__, 'autoptimize_uninstall' );
}
register_activation_hook( __FILE__, 'autoptimize_activate' );

This way the uninstall hook would only be registered once, not on every page load.

@bjork bjork changed the title from `register_uninstall_hook()` called on every page load results in multiple unnecessary database queries to `register_uninstall_hook()` called on every page load results into multiple unnecessary database queries Dec 26, 2016
@futtta
Owner
futtta commented Dec 26, 2016

good catch, can you issue a pull request? :-)

@futtta futtta closed this in #74 Dec 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment