Modifed "update" and "insert" function / many changed queries
This commit is contained in:
parent
a5e7f7bf70
commit
fce72cbbc8
11 changed files with 66 additions and 123 deletions
|
@ -6,6 +6,7 @@ use Friendica\Core\Config;
|
|||
use Friendica\Core\PConfig;
|
||||
|
||||
use Cache;
|
||||
use dba;
|
||||
use dbm;
|
||||
|
||||
use Detection\MobileDetect;
|
||||
|
@ -712,20 +713,20 @@ class App {
|
|||
|
||||
$this->remove_inactive_processes();
|
||||
|
||||
q('START TRANSACTION');
|
||||
dba::transaction();
|
||||
|
||||
$r = q('SELECT `pid` FROM `process` WHERE `pid` = %d', intval(getmypid()));
|
||||
if (!dbm::is_result($r)) {
|
||||
q("INSERT INTO `process` (`pid`,`command`,`created`) VALUES (%d, '%s', '%s')", intval(getmypid()), dbesc($command), dbesc(datetime_convert()));
|
||||
}
|
||||
q('COMMIT');
|
||||
dba::commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Remove inactive processes
|
||||
*/
|
||||
function remove_inactive_processes() {
|
||||
q('START TRANSACTION');
|
||||
dba::transaction();
|
||||
|
||||
$r = q('SELECT `pid` FROM `process`');
|
||||
if (dbm::is_result($r)) {
|
||||
|
@ -735,7 +736,7 @@ class App {
|
|||
}
|
||||
}
|
||||
}
|
||||
q('COMMIT');
|
||||
dba::commit();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -164,19 +164,11 @@ class Config {
|
|||
$dbvalue = (is_array($value) ? serialize($value) : $dbvalue);
|
||||
|
||||
if (is_null($stored) || !self::$in_db[$family][$key]) {
|
||||
$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)
|
||||
);
|
||||
dba::insert('config', array('cat' => $family, 'k' => $key, 'v' => $dbvalue), true);
|
||||
} else {
|
||||
$ret = q("UPDATE `config` SET `v` = '%s' WHERE `cat` = '%s' AND `k` = '%s'",
|
||||
dbesc($dbvalue),
|
||||
dbesc($family),
|
||||
dbesc($key)
|
||||
);
|
||||
dba::update('config', array('v' => $dbvalue), array('cat' => $family, 'k' => $key), true);
|
||||
}
|
||||
|
||||
if ($ret) {
|
||||
self::$in_db[$family][$key] = true;
|
||||
return $value;
|
||||
|
|
|
@ -142,20 +142,9 @@ class PConfig {
|
|||
$dbvalue = (is_array($value) ? serialize($value) : $dbvalue);
|
||||
|
||||
if (is_null($stored) || !self::$in_db[$uid][$family][$key]) {
|
||||
$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)
|
||||
);
|
||||
dba::insert('pconfig', array('uid' => $uid, 'cat' => $family, 'k' => $key, 'v' => $dbvalue), true);
|
||||
} 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)
|
||||
);
|
||||
dba::update('pconfig', array('v' => $dbvalue), array('uid' => $uid, 'cat' => $family, 'k' => $key), true);
|
||||
}
|
||||
|
||||
if ($ret) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue