Improved queries, more uncommitted queries

This commit is contained in:
Michael Vogel 2016-10-17 18:38:51 +00:00
parent e5c7ce0902
commit 3e5cf5290e
12 changed files with 141 additions and 75 deletions

View file

@ -132,15 +132,33 @@ class Config {
$dbvalue = (is_array($value)?serialize($value):$value);
$dbvalue = (is_bool($dbvalue) ? intval($dbvalue) : $dbvalue);
$ret = q("INSERT INTO `config` ( `cat`, `k`, `v` ) VALUES ( '%s', '%s', '%s' )
ON DUPLICATE KEY UPDATE `v` = '%s'",
// The "INSERT" command is very cost intense. It saves performance to do it this way.
$ret = q("SELECT `v` FROM `config` WHERE `cat` = '%s' AND `k` = '%s' ORDER BY `id` DESC LIMIT 1",
dbesc($family),
dbesc($key),
dbesc($dbvalue),
dbesc($dbvalue)
dbesc($key)
);
// It would be better to use the dbm class.
// But there is an autoloader issue that I don't know how to fix:
// "Class 'Friendica\Core\dbm' not found"
//if (!dbm::is_result($ret))
if (!$ret)
$ret = q("INSERT INTO `config` (`cat`, `k`, `v`) VALUES ('%s', '%s', '%s') ON DUPLICATE KEY UPDATE `v` = '%s'",
dbesc($family),
dbesc($key),
dbesc($dbvalue),
dbesc($dbvalue)
);
elseif ($ret[0]['v'] != $dbvalue)
$ret = q("UPDATE `config` SET `v` = '%s' WHERE `cat` = '%s' AND `k` = '%s'",
dbesc($dbvalue),
dbesc($family),
dbesc($key)
);
if($ret)
return $value;
return $ret;
}

View file

@ -128,14 +128,32 @@ class PConfig {
$a->config[$uid][$family][$key] = $value;
$ret = q("INSERT INTO `pconfig` ( `uid`, `cat`, `k`, `v` ) VALUES ( %d, '%s', '%s', '%s' )
ON DUPLICATE KEY UPDATE `v` = '%s'",
// 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),
dbesc($dbvalue),
dbesc($dbvalue)
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'",
intval($uid),
dbesc($family),
dbesc($key),
dbesc($dbvalue),
dbesc($dbvalue)
);
elseif ($ret[0]['v'] != $dbvalue)
$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)
return $value;
return $ret;