I was trying to debug something, and discovered that DM is once again reloading the Form_validation library on every model.
This isn’t huge a problem performance-wise, but it does tend to add a little more checking and loading than necessary, plus it fills the log files with “Form Validation Already loaded…” messages.
I would like to make a recommendation to only load the library the first time, as well as only calling the language and helper loading once.
My suggested (although probably not-very-elegant) solution is this:
// near top
static $common = array();
// add new variable to track whether anything has been loaded yet.
// Might be safe checking empty(DataMapper::$config) instead
static $_loaded_once = FALSE;// Add this to the constructor
function DataMapper()
{
$this->_assign_libraries();
if( ! DataMapper::$_loaded_once)
{
$this->_load_languages();
$this->_load_helpers();
DataMapper::$_loaded_once = TRUE;
}
// ...// modify _assign_libaries
function _assign_libraries()
{
if ($CI =& get_instance())
{
if( ! DataMapper::$_loaded_once) {
// Load CodeIgniters form validation
$CI->load->library('form_validation');
}Those few changes will prevent the libaries, language, and helper files from being loaded or checked dozens or even hundreds of times for very big datasets. Mostly, though, it will make debugging easier on me 😉
Also, a recommendation but not too important, does it make sense to migrate the date format code from being hard coded to being stored in the config file? This would allow users to change the format to whatever they wanted.