Pumpio: Optimised query

This commit is contained in:
Michael 2017-01-17 19:01:27 +00:00
parent d229fd28a2
commit fd0ef2f2c7

View file

@ -835,8 +835,8 @@ function pumpio_dounlike(&$a, $uid, $self, $post, $own_id) {
if(link_compare($post->actor->url, $own_id)) {
$contactid = $self[0]['id'];
} else {
$r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
dbesc($post->actor->url),
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
dbesc(normalise_link($post->actor->url)),
intval($uid)
);
@ -960,45 +960,17 @@ function pumpio_dolike(&$a, $uid, $self, $post, $own_id, $threadcompletion = tru
function pumpio_get_contact($uid, $contact, $no_insert = false) {
if (function_exists("update_gcontact")) {
update_gcontact(array("url" => $contact->url, "network" => NETWORK_PUMPIO, "generation" => 2,
"photo" => $contact->image->url, "name" => $contact->displayName, "hide" => true,
"nick" => $contact->preferredUsername, "location" => $contact->location->displayName,
"about" => $contact->summary, "addr" => str_replace("acct:", "", $contact->id)));
$cid = get_contact($contact->url, $uid);
} else {
// Old Code
$r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
dbesc(normalise_link($contact->url)));
if (count($r) == 0)
q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')",
dbesc(normalise_link($contact->url)),
dbesc($contact->displayName),
dbesc($contact->preferredUsername),
dbesc($contact->image->url));
else
q("UPDATE unique_contacts SET name = '%s', nick = '%s', avatar = '%s' WHERE url = '%s'",
dbesc($contact->displayName),
dbesc($contact->preferredUsername),
dbesc($contact->image->url),
dbesc(normalise_link($contact->url)));
if (DB_UPDATE_VERSION >= "1177")
q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'",
dbesc($contact->location->displayName),
dbesc($contact->summary),
dbesc(normalise_link($contact->url)));
$cid = 0;
}
if ($no_insert)
return($cid);
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' LIMIT 1",
intval($uid), dbesc($contact->url));
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1",
intval($uid), dbesc(normalise_link($contact->url)));
if (!count($r)) {
// create contact record
@ -1023,13 +995,14 @@ function pumpio_get_contact($uid, $contact, $no_insert = false) {
intval(1)
);
$r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
dbesc($contact->url),
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
dbesc(normalise_link($contact->url)),
intval($uid)
);
if(! count($r))
if (!count($r)) {
return(false);
}
$contact_id = $r[0]['id'];
@ -1168,16 +1141,16 @@ function pumpio_dopost(&$a, $client, $uid, $self, $post, $own_id, $threadcomplet
$post->actor->image->url = $self[0]['photo'];
} elseif ($contact_id == 0) {
// Take an existing contact, the contact of the note or - as a fallback - the id of the user
$r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
dbesc($post->actor->url),
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
dbesc(normalise_link($post->actor->url)),
intval($uid)
);
if(count($r))
$contact_id = $r[0]['id'];
else {
$r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
dbesc($post->actor->url),
$r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
dbesc(normalise_link($post->actor->url)),
intval($uid)
);