Some more updated queries
This commit is contained in:
parent
41a81624a2
commit
0ac725dc47
7 changed files with 26 additions and 27 deletions
|
@ -56,7 +56,7 @@ function contact_remove($id) {
|
|||
return;
|
||||
}
|
||||
|
||||
q("DELETE FROM `contact` WHERE `id` = %d", intval($id));
|
||||
dba::delete('contact', array('id' => $id));
|
||||
|
||||
// Delete the rest in the background
|
||||
proc_run(PRIORITY_LOW, 'include/remove_contact.php', $id);
|
||||
|
@ -617,8 +617,8 @@ function get_contact($url, $uid = 0, $no_update = false) {
|
|||
}
|
||||
|
||||
if (count($contacts) > 1 && $uid == 0 && $contact_id != 0 && $data["url"] != "") {
|
||||
dba::e("DELETE FROM `contact` WHERE `nurl` = ? AND `uid` = 0 AND `id` != ? AND NOT `self`",
|
||||
normalise_link($data["url"]), $contact_id);
|
||||
dba::delete('contact', array("`nurl` = ? AND `uid` = 0 AND `id` != ? AND NOT `self`",
|
||||
normalise_link($data["url"]), $contact_id));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -680,8 +680,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
|
|||
$hashtags = array();
|
||||
$mentions = array();
|
||||
|
||||
$taglist = dba::p("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = ? AND `oid` = ? AND `type` IN (?, ?) ORDER BY `tid`",
|
||||
intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));
|
||||
$taglist = dba::select('term', array('type', 'term', 'url'),
|
||||
array("`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION),
|
||||
array('order' => array('tid')));
|
||||
|
||||
while ($tag = dba::fetch($taglist)) {
|
||||
if ($tag["url"] == "") {
|
||||
|
|
|
@ -84,7 +84,7 @@ function cron_run(&$argv, &$argc){
|
|||
proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_photo_albums");
|
||||
|
||||
// Delete all done workerqueue entries
|
||||
dba::e('DELETE FROM `workerqueue` WHERE `done` AND `executed` < UTC_TIMESTAMP() - INTERVAL 12 HOUR');
|
||||
dba::delete('workerqueue', array('`done` AND `executed` < UTC_TIMESTAMP() - INTERVAL 12 HOUR'));
|
||||
}
|
||||
|
||||
// Poll contacts
|
||||
|
|
|
@ -474,8 +474,9 @@ function poller_max_connections_reached() {
|
|||
*
|
||||
*/
|
||||
function poller_kill_stale_workers() {
|
||||
$entries = dba::p("SELECT `id`, `pid`, `executed`, `priority`, `parameter` FROM `workerqueue` WHERE `executed` > ? AND NOT `done` AND `pid` != 0 ORDER BY `priority`, `created`", NULL_DATE);
|
||||
|
||||
$entries = dba::select('workerqueue', array('id', 'pid', 'executed', 'priority', 'parameter'),
|
||||
array('`executed` > ? AND NOT `done` AND `pid` != 0', NULL_DATE),
|
||||
array('order' => array('priority', 'created')));
|
||||
while ($entry = dba::fetch($entries)) {
|
||||
if (!posix_kill($entry["pid"], 0)) {
|
||||
dba::update('workerqueue', array('executed' => NULL_DATE, 'pid' => 0),
|
||||
|
@ -698,10 +699,8 @@ function find_worker_processes(&$passing_slow) {
|
|||
|
||||
if (poller_passing_slow($highest_priority)) {
|
||||
// Are there waiting processes with a higher priority than the currently highest?
|
||||
$result = dba::p("SELECT `id` FROM `workerqueue`
|
||||
WHERE `executed` <= ? AND `priority` < ? AND NOT `done`
|
||||
ORDER BY `priority`, `created` LIMIT ".intval($limit),
|
||||
NULL_DATE, $highest_priority);
|
||||
$result = dba::select('workerqueue', array('id'), array("`executed` <= ? AND `priority` < ? AND NOT `done`", NULL_DATE, $highest_priority),
|
||||
array('limit' => $limit, 'order' => array('priority', 'created'), 'only_query' => true));
|
||||
|
||||
while ($id = dba::fetch($result)) {
|
||||
$ids[] = $id["id"];
|
||||
|
@ -712,10 +711,8 @@ function find_worker_processes(&$passing_slow) {
|
|||
|
||||
if (!$found) {
|
||||
// Give slower processes some processing time
|
||||
$result = dba::p("SELECT `id` FROM `workerqueue`
|
||||
WHERE `executed` <= ? AND `priority` > ? AND NOT `done`
|
||||
ORDER BY `priority`, `created` LIMIT ".intval($limit),
|
||||
NULL_DATE, $highest_priority);
|
||||
$result = dba::select('workerqueue', array('id'), array("`executed` <= ? AND `priority` > ? AND NOT `done`", NULL_DATE, $highest_priority),
|
||||
array('limit' => $limit, 'order' => array('priority', 'created'), 'only_query' => true));
|
||||
|
||||
while ($id = dba::fetch($result)) {
|
||||
$ids[] = $id["id"];
|
||||
|
@ -729,7 +726,8 @@ function find_worker_processes(&$passing_slow) {
|
|||
|
||||
// If there is no result (or we shouldn't pass lower processes) we check without priority limit
|
||||
if (!$found) {
|
||||
$result = dba::p("SELECT `id` FROM `workerqueue` WHERE `executed` <= ? AND NOT `done` ORDER BY `priority`, `created` LIMIT ".intval($limit), NULL_DATE);
|
||||
$result = dba::select('workerqueue', array('id'), array("`executed` <= ? AND NOT `done`", NULL_DATE),
|
||||
array('limit' => $limit, 'order' => array('priority', 'created'), 'only_query' => true));
|
||||
|
||||
while ($id = dba::fetch($result)) {
|
||||
$ids[] = $id["id"];
|
||||
|
@ -740,9 +738,9 @@ function find_worker_processes(&$passing_slow) {
|
|||
}
|
||||
|
||||
if ($found) {
|
||||
$sql = "UPDATE `workerqueue` SET `executed` = ?, `pid` = ? WHERE `id` IN (".substr(str_repeat("?, ", count($ids)), 0, -2).") AND `pid` = 0 AND NOT `done`;";
|
||||
array_unshift($ids, datetime_convert(), $mypid);
|
||||
dba::e($sql, $ids);
|
||||
$condition = "`id` IN (".substr(str_repeat("?, ", count($ids)), 0, -2).") AND `pid` = 0 AND NOT `done`";
|
||||
array_unshift($ids, $condition);
|
||||
dba::update('workerqueue', array('executed' => datetime_convert(), 'pid' => $mypid), $ids);
|
||||
}
|
||||
|
||||
return $found;
|
||||
|
|
|
@ -1025,7 +1025,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
if (dbm::is_result($servers) && ($orig_server_url == $server_url) &&
|
||||
($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
|
||||
logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
|
||||
dba::p("UPDATE `gserver` SET `last_failure` = ? WHERE `nurl` = ?", datetime_convert(), normalise_link($server_url));
|
||||
dba::update('gserver', array('last_failure' => datetime_convert()), array('nurl' => normalise_link($server_url)));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1040,7 +1040,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
// Quit if there is a timeout
|
||||
if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) {
|
||||
logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
|
||||
dba::p("UPDATE `gserver` SET `last_failure` = ? WHERE `nurl` = ?", datetime_convert(), normalise_link($server_url));
|
||||
dba::update('gserver', array('last_failure' => datetime_convert()), array('nurl' => normalise_link($server_url)));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -262,7 +262,7 @@ function delete_thread($itemid, $itemuri = "") {
|
|||
function update_threads() {
|
||||
logger("update_threads: start");
|
||||
|
||||
$messages = dba::p("SELECT `id` FROM `item` WHERE `id` = `parent`");
|
||||
$messages = dba::select('item', array('id'), array("`id` = `parent`"));
|
||||
|
||||
logger("update_threads: fetched messages: ".dba::num_rows($messages));
|
||||
|
||||
|
@ -292,9 +292,9 @@ function update_threads_mention() {
|
|||
function update_shadow_copy() {
|
||||
logger("start");
|
||||
|
||||
$messages = dba::p("SELECT `iid` FROM `thread` WHERE `uid` != 0 AND `network` IN ('', ?, ?, ?)
|
||||
AND `visible` AND NOT `deleted` AND NOT `moderated` AND NOT `private` ORDER BY `created`",
|
||||
NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS);
|
||||
$condition = "`uid` != 0 AND `network` IN ('', ?, ?, ?) AND `visible` AND NOT `deleted` AND NOT `moderated` AND NOT `private`";
|
||||
$messages = dba::select('thread', array('iid'), array($condition, NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS),
|
||||
array('order' => 'created'));
|
||||
|
||||
logger("fetched messages: ".dba::num_rows($messages));
|
||||
while ($message = dba::fetch($messages))
|
||||
|
|
|
@ -80,7 +80,7 @@ function display_init(App $a) {
|
|||
// We really should change this need for the future since it scales very bad.
|
||||
$contactid = get_contact($r['owner-link'], local_user());
|
||||
if ($contactid) {
|
||||
$items = dba::p("SELECT * FROM `item` WHERE `parent` = ? ORDER BY `id`", $r["id"]);
|
||||
$items = dba::select('item', array(), array('parent' => $r["id"]), array('order' => array('id')));
|
||||
while ($item = dba::fetch($items)) {
|
||||
$itemcontactid = get_contact($item['owner-link'], local_user());
|
||||
if (!$itemcontactid) {
|
||||
|
|
Loading…
Reference in a new issue