[dev] Excess activity in pref drivers

Jeff Seifert seifert at everybody.org
Wed Jun 11 14:57:54 PDT 2003


In watching the preferences drivers, I noticed they had a tendency to
re-save the preferences shortly after loading them for the first time.
The reason is because, during the retrieve stage of the SQL and LDAP
drivers, the preferences get set as being dirty, even though we *just*
loaded them.

The following patch rectifies that, skipping the step in setting the
dirty bit when retrieving the value from the preference driver.

-Jeff

-------------- next part --------------
Index: horde/lib/Prefs.php
===================================================================
RCS file: /repository/horde/lib/Prefs.php,v
retrieving revision 1.109
diff -c -r1.109 Prefs.php
*** horde/lib/Prefs.php	10 Jun 2003 11:54:54 -0000	1.109
--- horde/lib/Prefs.php	11 Jun 2003 21:45:00 -0000
***************
*** 459,471 ****
       *
       * @access protected
       *
!      * @param string $pref  The name of the preference to modify.
!      * @param string $val   The new value for this preference.
       *
       * @return boolean  True if the value was successfully set, false on a
       *                  failure.
       */
!     function _setValue($pref, $val)
      {
          global $conf;
  
--- 459,473 ----
       *
       * @access protected
       *
!      * @param string  $pref   The name of the preference to modify.
!      * @param string  $val    The new value for this preference.
!      * @param boolean $dirty  True if we should mark the new value as
!      *                        dirty.
       *
       * @return boolean  True if the value was successfully set, false on a
       *                  failure.
       */
!     function _setValue($pref, $val, $dirty = true)
      {
          global $conf;
  
***************
*** 498,504 ****
          }
          $this->_prefs[$pref]['val'] = $val;
          $this->setDefault($pref, false);
!         $this->setDirty($pref, true);
  
          return true;
      }
--- 500,508 ----
          }
          $this->_prefs[$pref]['val'] = $val;
          $this->setDefault($pref, false);
!         if($dirty) {
!             $this->setDirty($pref, true);
!         }
  
          return true;
      }
Index: horde/lib/Prefs/sql.php
===================================================================
RCS file: /repository/horde/lib/Prefs/sql.php,v
retrieving revision 1.64
diff -c -r1.64 sql.php
*** horde/lib/Prefs/sql.php	10 Jun 2003 19:05:02 -0000	1.64
--- horde/lib/Prefs/sql.php	11 Jun 2003 21:45:05 -0000
***************
*** 273,279 ****
              while ($row && !is_a($row, 'PEAR_Error')) {
                  $name = trim($row['pref_name']);
                  if (in_array($name, $prefs)) {
!                     $this->_setValue($name, String::convertCharset($row['pref_value'], $this->_params['charset']));
                      $this->setDirty($name, false);
                  } else {
                      $this->add($name, String::convertCharset($row['pref_value'], $this->_params['charset']), _PREF_SHARED);
--- 273,279 ----
              while ($row && !is_a($row, 'PEAR_Error')) {
                  $name = trim($row['pref_name']);
                  if (in_array($name, $prefs)) {
!                     $this->_setValue($name, String::convertCharset($row['pref_value'], $this->_params['charset']), false);
                      $this->setDirty($name, false);
                  } else {
                      $this->add($name, String::convertCharset($row['pref_value'], $this->_params['charset']), _PREF_SHARED);
Index: horde/lib/Prefs/ldap.php
===================================================================
RCS file: /repository/horde/lib/Prefs/ldap.php,v
retrieving revision 1.67
diff -c -r1.67 ldap.php
*** horde/lib/Prefs/ldap.php	10 Jun 2003 18:16:24 -0000	1.67
--- horde/lib/Prefs/ldap.php	11 Jun 2003 21:45:08 -0000
***************
*** 421,427 ****
  
                  /* Retrieve this preference. */
                  if (isset($this->_prefs[$pref])) {
!                     $this->_setValue($pref, base64_decode($val));
                      $this->setDefault($pref, false);
                  } else {
                      $this->add($pref, base64_decode($val), _PREF_SHARED);
--- 421,427 ----
  
                  /* Retrieve this preference. */
                  if (isset($this->_prefs[$pref])) {
!                     $this->_setValue($pref, base64_decode($val), false);
                      $this->setDefault($pref, false);
                  } else {
                      $this->add($pref, base64_decode($val), _PREF_SHARED);
-------------- next part --------------

"heh heh..  He said "dirty bit".  heh heh.."

-- 
/* A programmer is a machine for turning coffee into code */


More information about the dev mailing list