]> git.mxchange.org Git - friendica.git/commitdiff
pconfig: Improved behaviour with already stored values
authorMichael Vogel <ike@pirati.ca>
Sun, 23 Oct 2016 07:49:21 +0000 (07:49 +0000)
committerMichael Vogel <ike@pirati.ca>
Sun, 23 Oct 2016 07:49:21 +0000 (07:49 +0000)
include/Core/Config.php
include/Core/PConfig.php
include/api.php

index 76a0abe24162a494ab306072e3d0c58efd0d7fb1..b56edb4c26f5fdc2176bf03ed68b4d94bdb33fc7 100644 (file)
@@ -144,7 +144,7 @@ class Config {
                                dbesc($dbvalue),
                                dbesc($dbvalue)
                        );
-               } elseif ($ret[0]['v'] != $dbvalue) {
+               } else {
                        $ret = q("UPDATE `config` SET `v` = '%s' WHERE `cat` = '%s' AND `k` = '%s'",
                                dbesc($dbvalue),
                                dbesc($family),
index 975210cfd2d608ea09487257d54efc3da3208365..fc022d62823e3d5af9fbb5294f5a482d70779b02 100644 (file)
@@ -122,22 +122,18 @@ class PConfig {
 
                global $a;
 
+               $stored = self::get($uid, $family, $key);
+
+               if ($stored == $value) {
+                       return true;
+               }
+
                // manage array value
                $dbvalue = (is_array($value) ? serialize($value):$value);
 
                $a->config[$uid][$family][$key] = $value;
 
-               // The "INSERT" command is very cost intense. It saves performance to do it this way.
-               $ret = q("SELECT `v` FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' ORDER BY `id` DESC LIMIT 1",
-                       intval($uid),
-                       dbesc($family),
-                       dbesc($key)
-               );
-
-               // It would be better to use the dbm class.
-               // My lacking knowdledge in autoloaders prohibits this.
-               // if (!dbm::is_result($ret))
-                if (!$ret)
+                if (is_null($stored)) {
                        $ret = q("INSERT INTO `pconfig` (`uid`, `cat`, `k`, `v`) VALUES (%d, '%s', '%s', '%s') ON DUPLICATE KEY UPDATE `v` = '%s'",
                                intval($uid),
                                dbesc($family),
@@ -145,17 +141,18 @@ class PConfig {
                                dbesc($dbvalue),
                                dbesc($dbvalue)
                        );
-               elseif ($ret[0]['v'] != $dbvalue)
+               } else {
                        $ret = q("UPDATE `pconfig` SET `v` = '%s' WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s'",
                                dbesc($dbvalue),
                                intval($uid),
                                dbesc($family),
                                dbesc($key)
                        );
+               }
 
-               if ($ret)
+               if ($ret) {
                        return $value;
-
+               }
                return $ret;
        }
 
@@ -175,13 +172,17 @@ class PConfig {
        public static function delete($uid,$family,$key) {
 
                global $a;
-               if (x($a->config[$uid][$family], $key))
+
+               if (x($a->config[$uid][$family], $key)) {
                        unset($a->config[$uid][$family][$key]);
+               }
+
                $ret = q("DELETE FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s'",
                        intval($uid),
                        dbesc($family),
                        dbesc($key)
                );
+
                return $ret;
        }
 }
index af7c2ca523efc29613b4390c48f8bd2d3160df7d..1a6eea88ef7f435dc2b9fb5213b5ed9efe022689 100644 (file)
 
                        //AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
                        // count public wall messages
-                       $r = q("SELECT COUNT(*) as `count` FROM `item` WHERE `uid` = %d AND wall",
+                       $r = q("SELECT COUNT(*) as `count` FROM `item` WHERE `uid` = %d AND `wall`",
                                        intval($uinfo[0]['uid'])
                        );
                        $countitms = $r[0]['count'];