Suggest only active accounts. Remove duplicates from gcontact table.
This commit is contained in:
parent
47560fc6c7
commit
d49c3e99ac
2 changed files with 29 additions and 14 deletions
|
@ -413,6 +413,8 @@ function db_definition() {
|
|||
"network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"about" => array("type" => "text", "not null" => "1"),
|
||||
"attag" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
"photo" => array("type" => "text", "not null" => "1"),
|
||||
"thumb" => array("type" => "text", "not null" => "1"),
|
||||
|
|
|
@ -98,7 +98,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
|
|||
if((! $name) || (! $profile_url) || (! $profile_photo))
|
||||
continue;
|
||||
|
||||
$x = q("select * from `gcontact` where `nurl` = '%s' limit 1",
|
||||
$x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
|
||||
dbesc(normalise_link($profile_url))
|
||||
);
|
||||
|
||||
|
@ -116,8 +116,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
|
|||
dbesc(normalise_link($profile_url))
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`,`connect`, `updated`)
|
||||
values ( '%s', '%s', '%s', '%s','%s') ",
|
||||
dbesc($name),
|
||||
|
@ -127,7 +126,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
|
|||
dbesc($connect_url),
|
||||
dbesc($updated)
|
||||
);
|
||||
$x = q("select * from `gcontact` where `nurl` = '%s' limit 1",
|
||||
$x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
|
||||
dbesc(normalise_link($profile_url))
|
||||
);
|
||||
if(count($x))
|
||||
|
@ -136,14 +135,14 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
|
|||
if(! $gcid)
|
||||
return;
|
||||
|
||||
$r = q("select * from glink where `cid` = %d and `uid` = %d and `gcid` = %d and `zcid` = %d limit 1",
|
||||
$r = q("SELECT * FROM `glink` WHERE `cid` = %d AND `uid` = %d AND `gcid` = %d AND `zcid` = %d LIMIT 1",
|
||||
intval($cid),
|
||||
intval($uid),
|
||||
intval($gcid),
|
||||
intval($zcid)
|
||||
);
|
||||
if(! count($r)) {
|
||||
q("insert into glink ( `cid`,`uid`,`gcid`,`zcid`, `updated`) values (%d,%d,%d,%d, '%s') ",
|
||||
q("INSERT INTO `glink` (`cid`,`uid`,`gcid`,`zcid`, `updated`) VALUES (%d,%d,%d,%d, '%s') ",
|
||||
intval($cid),
|
||||
intval($uid),
|
||||
intval($gcid),
|
||||
|
@ -152,7 +151,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
|
|||
);
|
||||
}
|
||||
else {
|
||||
q("update glink set updated = '%s' where `cid` = %d and `uid` = %d and `gcid` = %d and zcid = %d",
|
||||
q("UPDATE `glink` SET `updated` = '%s' WHERE `cid` = %d AND `uid` = %d AND `gcid` = %d AND `zcid` = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($cid),
|
||||
intval($uid),
|
||||
|
@ -161,10 +160,17 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
|
|||
);
|
||||
}
|
||||
|
||||
// For unknown reasons there are sometimes duplicates
|
||||
q("DELETE FROM `gcontact` WHERE `nurl` = '%s' AND `id` != %d AND
|
||||
NOT EXISTS (SELECT `gcid` FROM `glink` WHERE `gcid` = `gcontact`.`id`)",
|
||||
dbesc(normalise_link($profile_url)),
|
||||
intval($gcid)
|
||||
);
|
||||
|
||||
}
|
||||
logger("poco_load: loaded $total entries",LOGGER_DEBUG);
|
||||
|
||||
q("delete from glink where `cid` = %d and `uid` = %d and `zcid` = %d and `updated` < UTC_TIMESTAMP - INTERVAL 2 DAY",
|
||||
q("DELETE FROM `glink` WHERE `cid` = %d AND `uid` = %d AND `zcid` = %d AND `updated` < UTC_TIMESTAMP - INTERVAL 2 DAY",
|
||||
intval($cid),
|
||||
intval($uid),
|
||||
intval($zcid)
|
||||
|
@ -295,12 +301,13 @@ function suggestion_query($uid, $start = 0, $limit = 80) {
|
|||
if(! $uid)
|
||||
return array();
|
||||
|
||||
$r = q("SELECT count(glink.gcid) as `total`, gcontact.* from gcontact
|
||||
INNER JOIN glink on glink.gcid = gcontact.id
|
||||
$r = q("SELECT count(glink.gcid) as `total`, gcontact.* from gcontact
|
||||
INNER JOIN glink on glink.gcid = gcontact.id
|
||||
where uid = %d and not gcontact.nurl in ( select nurl from contact where uid = %d )
|
||||
and not gcontact.name in ( select name from contact where uid = %d )
|
||||
and not gcontact.id in ( select gcid from gcign where uid = %d )
|
||||
group by glink.gcid order by total desc limit %d, %d ",
|
||||
AND `gcontact`.`updated` != '0000-00-00 00:00:00'
|
||||
group by glink.gcid order by gcontact.updated desc,total desc limit %d, %d ",
|
||||
intval($uid),
|
||||
intval($uid),
|
||||
intval($uid),
|
||||
|
@ -312,11 +319,12 @@ function suggestion_query($uid, $start = 0, $limit = 80) {
|
|||
if(count($r) && count($r) >= ($limit -1))
|
||||
return $r;
|
||||
|
||||
$r2 = q("SELECT gcontact.* from gcontact
|
||||
INNER JOIN glink on glink.gcid = gcontact.id
|
||||
$r2 = q("SELECT gcontact.* from gcontact
|
||||
INNER JOIN glink on glink.gcid = gcontact.id
|
||||
where glink.uid = 0 and glink.cid = 0 and glink.zcid = 0 and not gcontact.nurl in ( select nurl from contact where uid = %d )
|
||||
and not gcontact.name in ( select name from contact where uid = %d )
|
||||
and not gcontact.id in ( select gcid from gcign where uid = %d )
|
||||
AND `gcontact`.`updated` != '0000-00-00 00:00:00'
|
||||
order by rand() limit %d, %d ",
|
||||
intval($uid),
|
||||
intval($uid),
|
||||
|
@ -325,9 +333,14 @@ function suggestion_query($uid, $start = 0, $limit = 80) {
|
|||
intval($limit)
|
||||
);
|
||||
|
||||
$list = array();
|
||||
foreach ($r2 AS $suggestion)
|
||||
$list[$suggestion["nurl"]] = $suggestion;
|
||||
|
||||
return array_merge($r,$r2);
|
||||
foreach ($r AS $suggestion)
|
||||
$list[$suggestion["nurl"]] = $suggestion;
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
function update_suggestions() {
|
||||
|
|
Loading…
Reference in a new issue