replace "p" with higher level database functions

This commit is contained in:
Michael 2021-10-12 05:53:29 +00:00
parent 948450c24b
commit 27b9da3df5
8 changed files with 30 additions and 71 deletions

View file

@ -3013,37 +3013,29 @@ class Contact
}
// check supported networks
$networks = [Protocol::DFRN, Protocol::ACTIVITYPUB];
if (DI::config()->get('system', 'diaspora_enabled')) {
$diaspora = Protocol::DIASPORA;
} else {
$diaspora = Protocol::DFRN;
$networks[] = Protocol::DIASPORA;
}
if (!DI::config()->get('system', 'ostatus_disabled')) {
$ostatus = Protocol::OSTATUS;
} else {
$ostatus = Protocol::DFRN;
$networks[] = Protocol::OSTATUS;
}
$condition = ['network' => $networks, 'failed' => false, 'uid' => $uid];
// check if we search only communities or every contact
if ($mode === 'community') {
$extra_sql = sprintf(' AND `contact-type` = %d', self::TYPE_COMMUNITY);
} else {
$extra_sql = '';
$condition['contact-type'] = self::TYPE_COMMUNITY;
}
$search .= '%';
$results = DBA::p("SELECT * FROM `contact`
WHERE (NOT `unsearchable` OR `nurl` IN (SELECT `nurl` FROM `owner-view` where `publish` OR `net-publish`))
AND `network` IN (?, ?, ?, ?) AND
NOT `failed` AND `uid` = ? AND
(`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?) $extra_sql
ORDER BY `nurl` DESC LIMIT 1000",
Protocol::DFRN, Protocol::ACTIVITYPUB, $ostatus, $diaspora, $uid, $search, $search, $search
);
$condition = DBA::mergeConditions($condition,
["(NOT `unsearchable` OR `nurl` IN (SELECT `nurl` FROM `owner-view` where `publish` OR `net-publish`))
AND (`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?)", $search, $search, $search]);
$contacts = DBA::toArray($results);
$contacts = self::selectToArray([], $condition);
return $contacts;
}

View file

@ -1667,14 +1667,10 @@ class GServer
$last_update = date('c', time() - (60 * 60 * 24 * $requery_days));
$gservers = DBA::p("SELECT `id`, `url`, `nurl`, `network`, `poco`, `directory-type`
FROM `gserver`
WHERE NOT `failed`
AND `directory-type` != ?
AND `last_poco_query` < ?
ORDER BY RAND()", self::DT_NONE, $last_update
);
$gservers = DBA::select('gserver', ['id', 'url', 'nurl', 'network', 'poco', 'directory-type'],
["NOT `failed` AND `directory-type` != ? AND `last_poco_query` < ?", GServer::DT_NONE, $last_update],
['order' => ['RAND()']]);
while ($gserver = DBA::fetch($gservers)) {
Logger::info('Update peer list', ['server' => $gserver['url'], 'id' => $gserver['id']]);
Worker::add(PRIORITY_LOW, 'UpdateServerPeers', $gserver['url']);