Commit 9b4e9437 authored by KR Moorhouse's avatar KR Moorhouse

Replaced update_option calls to the cache with our own helper method.

parent 7e531c38
......@@ -127,7 +127,7 @@ class NF_AJAX_Controllers_Form extends NF_Abstracts_Controller
}
delete_user_option( get_current_user_id(), 'nf_form_preview_' . $form_data['id'] );
update_option( 'nf_form_' . $form_data[ 'id' ], $form_data );
WPN_Helper::update_nf_cache( $form_data[ 'id' ], $form_data );
do_action( 'ninja_forms_save_form', $form->get_id() );
......
......@@ -209,7 +209,7 @@ class NF_Admin_Processes_ChunkPublish extends NF_Abstracts_BatchProcess
}
delete_user_option( get_current_user_id(), 'nf_form_preview_' . $form_data['id'] );
update_option( 'nf_form_' . $form_data[ 'id' ], $form_data );
WPN_Helper::update_nf_cache( $form_data[ 'id' ], $form_data );
do_action( 'ninja_forms_save_form', $form->get_id() );
......
......@@ -195,7 +195,7 @@ final class NF_Database_Models_Form extends NF_Abstracts_Model
));
}
update_option( 'nf_form_' . $form_id, $form_cache );
WPN_Helper::update_nf_cache( $form_id, $form_cache );
add_action( 'admin_notices', array( 'NF_Database_Models_Form', 'import_admin_notice' ) );
......
......@@ -332,7 +332,7 @@ final class NF_Display_Render
}
if( $cache_updated ) {
update_option('nf_form_' . $form_id, $form_cache); // Update form cache without duplicate fields.
WPN_Helper::update_nf_cache( $form_id, $form_cache ); // Update form cache without duplicate fields.
}
}
......
......@@ -263,18 +263,53 @@ final class WPN_Helper
/**
* Function to fetch our cache from the upgrades table (if it exists there).
*
* @param $id (int) The form ID.
*/
public static function get_nf_cache( $id ) {
// See if we have the data in our table already.
global $wpdb;
$sql = "SELECT cache FROM `{$wpdb->prefix}nf3_upgrades` WHERE id = " . intval( $id );
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
// If so...
if ( ! empty( $result ) ) {
return $result[ 0 ][ 'cache' ];
}
// Unserialize the result.
$value = WPN_Helper::maybe_unserialize( $result[ 0 ][ 'cache' ] );
// Return it.
return $value;
} // Otherwise... (We don't have the data.)
else {
// Get it from the options table.
return get_option( 'nf_form_' . $id );
}
}
/**
* Function to insert or update our cache in the upgrades table (if it exists).
*
* @param $id (int) The form ID.
* @param $data (string) The form cache.
*/
public static function update_nf_cache( $id, $data ) {
// Define our current stage here for use as we run various upgrades.
$CURRENT_STAGE = 0;
// Serialize our data.
$cache = serialize( $data );
global $wpdb;
// See if we've already got a record.
$sql = "SELECT id FROM `{$wpdb->prefix}nf3_upgrades` WHERE id = " . intval( $id );
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
// If we don't already have the data...
if ( empty( $result ) ) {
// Insert it.
$sql = "INSERT INTO `{$wpdb->prefix}nf3_upgrades` (id, cache, stage) VALUES (" . intval( $id ) . ", '{$cache}', {$CURRENT_STAGE})";
} // Otherwise... (We do have the data.)
else {
// Update the existing record.
$sql = "UPDATE `{$wpdb->prefix}nf3_upgrades` SET cache = '{$cache}' WHERE id = " . intval( $id );
}
$wpdb->query( $sql );
}
private static function parse_utf8_serialized( $matches )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment