pconfig: Improved behaviour with already stored values

This commit is contained in:
Michael Vogel 2016-10-23 07:49:21 +00:00
parent 561f45b83b
commit deb2fee2f0
3 changed files with 18 additions and 17 deletions

View File

@ -144,7 +144,7 @@ class Config {
dbesc($dbvalue), dbesc($dbvalue),
dbesc($dbvalue) dbesc($dbvalue)
); );
} elseif ($ret[0]['v'] != $dbvalue) { } else {
$ret = q("UPDATE `config` SET `v` = '%s' WHERE `cat` = '%s' AND `k` = '%s'", $ret = q("UPDATE `config` SET `v` = '%s' WHERE `cat` = '%s' AND `k` = '%s'",
dbesc($dbvalue), dbesc($dbvalue),
dbesc($family), dbesc($family),

View File

@ -122,22 +122,18 @@ class PConfig {
global $a; global $a;
$stored = self::get($uid, $family, $key);
if ($stored == $value) {
return true;
}
// manage array value // manage array value
$dbvalue = (is_array($value) ? serialize($value):$value); $dbvalue = (is_array($value) ? serialize($value):$value);
$a->config[$uid][$family][$key] = $value; $a->config[$uid][$family][$key] = $value;
// The "INSERT" command is very cost intense. It saves performance to do it this way. if (is_null($stored)) {
$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)
$ret = q("INSERT INTO `pconfig` (`uid`, `cat`, `k`, `v`) VALUES (%d, '%s', '%s', '%s') ON DUPLICATE KEY UPDATE `v` = '%s'", $ret = q("INSERT INTO `pconfig` (`uid`, `cat`, `k`, `v`) VALUES (%d, '%s', '%s', '%s') ON DUPLICATE KEY UPDATE `v` = '%s'",
intval($uid), intval($uid),
dbesc($family), dbesc($family),
@ -145,17 +141,18 @@ class PConfig {
dbesc($dbvalue), dbesc($dbvalue),
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'", $ret = q("UPDATE `pconfig` SET `v` = '%s' WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s'",
dbesc($dbvalue), dbesc($dbvalue),
intval($uid), intval($uid),
dbesc($family), dbesc($family),
dbesc($key) dbesc($key)
); );
}
if ($ret) if ($ret) {
return $value; return $value;
}
return $ret; return $ret;
} }
@ -175,13 +172,17 @@ class PConfig {
public static function delete($uid,$family,$key) { public static function delete($uid,$family,$key) {
global $a; global $a;
if (x($a->config[$uid][$family], $key))
if (x($a->config[$uid][$family], $key)) {
unset($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'", $ret = q("DELETE FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s'",
intval($uid), intval($uid),
dbesc($family), dbesc($family),
dbesc($key) dbesc($key)
); );
return $ret; return $ret;
} }
} }

View File

@ -565,7 +565,7 @@
//AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''", //AND `allow_cid`='' AND `allow_gid`='' AND `deny_cid`='' AND `deny_gid`=''",
// count public wall messages // 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']) intval($uinfo[0]['uid'])
); );
$countitms = $r[0]['count']; $countitms = $r[0]['count'];