]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Further fixes to Managed_DataObject::_allCacheKeys(): now uses self::multicacheKey...
authorBrion Vibber <brion@pobox.com>
Thu, 29 Sep 2011 22:21:52 +0000 (15:21 -0700)
committerBrion Vibber <brion@pobox.com>
Thu, 29 Sep 2011 22:21:52 +0000 (15:21 -0700)
This should resolve the issues darkip was reporting with user_im_prefs entries returning null immediately after insertion (seen with memcached off, so it was happening even with the built-in in-process cache in the Cache base class).

What was happening was that the initial pkeyGet() would end up saving a negative cache entry under the form with the fields sorted in the key, as via multicacheKey():

    'statusnet:blaguette:user_im_prefs:screenname,transport:brionv,sms' => 'N;'

then we'd do an insert() on the new entry, saving cache entries for the non-sorted key names returned by _allCacheKeys():

    'statusnet:blaguette:user_im_prefs:transport,screenname:sms,brionv' => 'O...'
    'statusnet:blaguette:user_im_prefs:user_id,transport:1234,sms' => 'O...'

but the next query via pkeyGet() still saw the negative lookup cache from before, and came back with null.

Now, _allCacheKeys() sorts the fields in the keys by using the same key-builder function, and queries pick up the same thing you just inserted. :)

classes/Managed_DataObject.php

index ba2883450c1e06d6d3c78171eb7dc87a8ecebc59..1d55537e20b800c3fe5ec70b130406a3397fcaa4 100644 (file)
@@ -182,14 +182,13 @@ abstract class Managed_DataObject extends Memcached_DataObject
         $ckeys = array();
 
         if (!empty($table['unique keys'])) {
         $ckeys = array();
 
         if (!empty($table['unique keys'])) {
-            foreach ($table['unique keys'] as $idx => $fields) {
+            $keyNames = $table['unique keys'];
+            foreach ($keyNames as $idx => $fields) {
                 $val = array();
                 foreach ($fields as $name) {
                 $val = array();
                 foreach ($fields as $name) {
-                    $val[] = self::valueString($this->$name);
+                    $val[$name] = self::valueString($this->$name);
                 }
                 }
-                $keys = implode(',', $fields);
-                $vals = implode(',', $val);
-                $ckeys[] = $this->cacheKey($this->tableName(), $keys, $vals);
+                $ckeys[] = self::multicacheKey($this->tableName(), $val);
             }
         }
 
             }
         }
 
@@ -197,11 +196,9 @@ abstract class Managed_DataObject extends Memcached_DataObject
             $fields = $table['primary key'];
             $val = array();
             foreach ($fields as $name) {
             $fields = $table['primary key'];
             $val = array();
             foreach ($fields as $name) {
-                $val[] = self::valueString($this->$name);
+                $val[$name] = self::valueString($this->$name);
             }
             }
-            $keys = implode(',', $fields);
-            $vals = implode(',', $val);
-            $ckeys[] = $this->cacheKey($this->tableName(), $keys, $vals);
+            $ckeys[] = self::multicacheKey($this->tableName(), $val);
         }
         return $ckeys;
     }
         }
         return $ckeys;
     }