Some more updated queries

This commit is contained in:
Michael 2017-08-12 22:15:16 +00:00
parent 41a81624a2
commit 0ac725dc47
7 changed files with 26 additions and 27 deletions

View file

@ -56,7 +56,7 @@ function contact_remove($id) {
return; return;
} }
q("DELETE FROM `contact` WHERE `id` = %d", intval($id)); dba::delete('contact', array('id' => $id));
// Delete the rest in the background // Delete the rest in the background
proc_run(PRIORITY_LOW, 'include/remove_contact.php', $id); 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"] != "") { 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`", dba::delete('contact', array("`nurl` = ? AND `uid` = 0 AND `id` != ? AND NOT `self`",
normalise_link($data["url"]), $contact_id); normalise_link($data["url"]), $contact_id));
} }
} }

View file

@ -680,8 +680,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$hashtags = array(); $hashtags = array();
$mentions = array(); $mentions = array();
$taglist = dba::p("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = ? AND `oid` = ? AND `type` IN (?, ?) ORDER BY `tid`", $taglist = dba::select('term', array('type', 'term', 'url'),
intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION)); 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)) { while ($tag = dba::fetch($taglist)) {
if ($tag["url"] == "") { if ($tag["url"] == "") {

View file

@ -84,7 +84,7 @@ function cron_run(&$argv, &$argc){
proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_photo_albums"); proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_photo_albums");
// Delete all done workerqueue entries // 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 // Poll contacts

View file

@ -474,8 +474,9 @@ function poller_max_connections_reached() {
* *
*/ */
function poller_kill_stale_workers() { 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)) { while ($entry = dba::fetch($entries)) {
if (!posix_kill($entry["pid"], 0)) { if (!posix_kill($entry["pid"], 0)) {
dba::update('workerqueue', array('executed' => NULL_DATE, '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)) { if (poller_passing_slow($highest_priority)) {
// Are there waiting processes with a higher priority than the currently highest? // Are there waiting processes with a higher priority than the currently highest?
$result = dba::p("SELECT `id` FROM `workerqueue` $result = dba::select('workerqueue', array('id'), array("`executed` <= ? AND `priority` < ? AND NOT `done`", NULL_DATE, $highest_priority),
WHERE `executed` <= ? AND `priority` < ? AND NOT `done` array('limit' => $limit, 'order' => array('priority', 'created'), 'only_query' => true));
ORDER BY `priority`, `created` LIMIT ".intval($limit),
NULL_DATE, $highest_priority);
while ($id = dba::fetch($result)) { while ($id = dba::fetch($result)) {
$ids[] = $id["id"]; $ids[] = $id["id"];
@ -712,10 +711,8 @@ function find_worker_processes(&$passing_slow) {
if (!$found) { if (!$found) {
// Give slower processes some processing time // Give slower processes some processing time
$result = dba::p("SELECT `id` FROM `workerqueue` $result = dba::select('workerqueue', array('id'), array("`executed` <= ? AND `priority` > ? AND NOT `done`", NULL_DATE, $highest_priority),
WHERE `executed` <= ? AND `priority` > ? AND NOT `done` array('limit' => $limit, 'order' => array('priority', 'created'), 'only_query' => true));
ORDER BY `priority`, `created` LIMIT ".intval($limit),
NULL_DATE, $highest_priority);
while ($id = dba::fetch($result)) { while ($id = dba::fetch($result)) {
$ids[] = $id["id"]; $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 there is no result (or we shouldn't pass lower processes) we check without priority limit
if (!$found) { 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)) { while ($id = dba::fetch($result)) {
$ids[] = $id["id"]; $ids[] = $id["id"];
@ -740,9 +738,9 @@ function find_worker_processes(&$passing_slow) {
} }
if ($found) { if ($found) {
$sql = "UPDATE `workerqueue` SET `executed` = ?, `pid` = ? WHERE `id` IN (".substr(str_repeat("?, ", count($ids)), 0, -2).") AND `pid` = 0 AND NOT `done`;"; $condition = "`id` IN (".substr(str_repeat("?, ", count($ids)), 0, -2).") AND `pid` = 0 AND NOT `done`";
array_unshift($ids, datetime_convert(), $mypid); array_unshift($ids, $condition);
dba::e($sql, $ids); dba::update('workerqueue', array('executed' => datetime_convert(), 'pid' => $mypid), $ids);
} }
return $found; return $found;

View file

@ -1025,7 +1025,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
if (dbm::is_result($servers) && ($orig_server_url == $server_url) && if (dbm::is_result($servers) && ($orig_server_url == $server_url) &&
($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) { ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG); 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; return false;
} }
@ -1040,7 +1040,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
// Quit if there is a timeout // Quit if there is a timeout
if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) { if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) {
logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG); 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; return false;
} }

View file

@ -262,7 +262,7 @@ function delete_thread($itemid, $itemuri = "") {
function update_threads() { function update_threads() {
logger("update_threads: start"); 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)); logger("update_threads: fetched messages: ".dba::num_rows($messages));
@ -292,9 +292,9 @@ function update_threads_mention() {
function update_shadow_copy() { function update_shadow_copy() {
logger("start"); logger("start");
$messages = dba::p("SELECT `iid` FROM `thread` WHERE `uid` != 0 AND `network` IN ('', ?, ?, ?) $condition = "`uid` != 0 AND `network` IN ('', ?, ?, ?) AND `visible` AND NOT `deleted` AND NOT `moderated` AND NOT `private`";
AND `visible` AND NOT `deleted` AND NOT `moderated` AND NOT `private` ORDER BY `created`", $messages = dba::select('thread', array('iid'), array($condition, NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS),
NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS); array('order' => 'created'));
logger("fetched messages: ".dba::num_rows($messages)); logger("fetched messages: ".dba::num_rows($messages));
while ($message = dba::fetch($messages)) while ($message = dba::fetch($messages))

View file

@ -80,7 +80,7 @@ function display_init(App $a) {
// We really should change this need for the future since it scales very bad. // We really should change this need for the future since it scales very bad.
$contactid = get_contact($r['owner-link'], local_user()); $contactid = get_contact($r['owner-link'], local_user());
if ($contactid) { 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)) { while ($item = dba::fetch($items)) {
$itemcontactid = get_contact($item['owner-link'], local_user()); $itemcontactid = get_contact($item['owner-link'], local_user());
if (!$itemcontactid) { if (!$itemcontactid) {