From 0ac725dc471d9541ec4fb40a8fbcf3982116eb64 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 12 Aug 2017 22:15:16 +0000 Subject: [PATCH] Some more updated queries --- include/Contact.php | 6 +++--- include/conversation.php | 5 +++-- include/cron.php | 2 +- include/poller.php | 26 ++++++++++++-------------- include/socgraph.php | 4 ++-- include/threads.php | 8 ++++---- mod/display.php | 2 +- 7 files changed, 26 insertions(+), 27 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 1d49d4eeba..00c25df83e 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -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)); } } diff --git a/include/conversation.php b/include/conversation.php index 7c044a672c..f81fb3eb8d 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -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"] == "") { diff --git a/include/cron.php b/include/cron.php index eda88dbcd3..ccac49b637 100644 --- a/include/cron.php +++ b/include/cron.php @@ -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 diff --git a/include/poller.php b/include/poller.php index 4831ff0747..8c30d16285 100644 --- a/include/poller.php +++ b/include/poller.php @@ -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; diff --git a/include/socgraph.php b/include/socgraph.php index 55e0e6fc3a..ace1b916eb 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -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; } diff --git a/include/threads.php b/include/threads.php index bb978bc774..c1277778e6 100644 --- a/include/threads.php +++ b/include/threads.php @@ -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)) diff --git a/mod/display.php b/mod/display.php index 59ff7082cf..4adb860f39 100644 --- a/mod/display.php +++ b/mod/display.php @@ -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) { -- 2.39.5