]> git.mxchange.org Git - friendica.git/commitdiff
Some more updated queries
authorMichael <heluecht@pirati.ca>
Sat, 12 Aug 2017 22:15:16 +0000 (22:15 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 12 Aug 2017 22:15:16 +0000 (22:15 +0000)
include/Contact.php
include/conversation.php
include/cron.php
include/poller.php
include/socgraph.php
include/threads.php
mod/display.php

index 1d49d4eeba88d03103b9649088d891bb9559462e..00c25df83e22ca050ae55416623e41b28b4221ba 100644 (file)
@@ -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));
                }
        }
 
index 7c044a672ca18dbba34c91e7b3502b81afb92a7e..f81fb3eb8dc68ee1839c72ce9d3747fe4b871fd6 100644 (file)
@@ -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"] == "") {
index eda88dbcd3f17e307bfebcff6fd35308a5d5ced2..ccac49b637b7c901ed8acf81a74df795c7bc540e 100644 (file)
@@ -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
index 4831ff074743eef3e87ed8dd2317763522574eff..8c30d1628545e9ee5f3f41ce42804b04ec2d065a 100644 (file)
@@ -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;
index 55e0e6fc3a98a560c32573c442707e7c39de878a..ace1b916eb508e208bf1055a3f9016097d19cf7f 100644 (file)
@@ -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;
                }
 
index bb978bc77428f05a962e9d3c355daa149043b20d..c1277778e64f4788332b03abf7281790bce6c837 100644 (file)
@@ -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))
index 59ff7082cfbac7f95d5d1935af1135bc903a5f40..4adb860f39ed29f1bfb87b7e980e1dc3e5471b1a 100644 (file)
@@ -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) {