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)) { if(link_compare($post->actor->url, $own_id)) {
$contactid = $self[0]['id']; $contactid = $self[0]['id'];
} else { } else {
$r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
dbesc($post->actor->url), dbesc(normalise_link($post->actor->url)),
intval($uid) intval($uid)
); );
@ -960,52 +960,24 @@ function pumpio_dolike(&$a, $uid, $self, $post, $own_id, $threadcompletion = tru
function pumpio_get_contact($uid, $contact, $no_insert = false) { 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, update_gcontact(array("url" => $contact->url, "network" => NETWORK_PUMPIO, "generation" => 2,
"photo" => $contact->image->url, "name" => $contact->displayName, "hide" => true, "photo" => $contact->image->url, "name" => $contact->displayName, "hide" => true,
"nick" => $contact->preferredUsername, "location" => $contact->location->displayName, "nick" => $contact->preferredUsername, "location" => $contact->location->displayName,
"about" => $contact->summary, "addr" => str_replace("acct:", "", $contact->id))); "about" => $contact->summary, "addr" => str_replace("acct:", "", $contact->id)));
$cid = get_contact($contact->url, $uid); $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) if ($no_insert)
return($cid); return($cid);
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1",
intval($uid), dbesc($contact->url)); intval($uid), dbesc(normalise_link($contact->url)));
if(!count($r)) { if (!count($r)) {
// create contact record // create contact record
q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
`name`, `nick`, `photo`, `network`, `rel`, `priority`, `name`, `nick`, `photo`, `network`, `rel`, `priority`,
`writable`, `blocked`, `readonly`, `pending` ) `writable`, `blocked`, `readonly`, `pending` )
VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ", VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0)",
intval($uid), intval($uid),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc($contact->url), dbesc($contact->url),
@ -1023,13 +995,14 @@ function pumpio_get_contact($uid, $contact, $no_insert = false) {
intval(1) intval(1)
); );
$r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
dbesc($contact->url), dbesc(normalise_link($contact->url)),
intval($uid) intval($uid)
); );
if(! count($r)) if (!count($r)) {
return(false); return(false);
}
$contact_id = $r[0]['id']; $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']; $post->actor->image->url = $self[0]['photo'];
} elseif ($contact_id == 0) { } elseif ($contact_id == 0) {
// Take an existing contact, the contact of the note or - as a fallback - the id of the user // 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", $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
dbesc($post->actor->url), dbesc(normalise_link($post->actor->url)),
intval($uid) intval($uid)
); );
if(count($r)) if(count($r))
$contact_id = $r[0]['id']; $contact_id = $r[0]['id'];
else { else {
$r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `blocked` = 0 AND `readonly` = 0 LIMIT 1",
dbesc($post->actor->url), dbesc(normalise_link($post->actor->url)),
intval($uid) intval($uid)
); );