Three more joins replaced with views
This commit is contained in:
parent
1c980c5b29
commit
ee3a724b41
2 changed files with 37 additions and 57 deletions
|
@ -887,30 +887,25 @@ class Profile
|
||||||
*/
|
*/
|
||||||
public static function searchProfiles($start = 0, $count = 100, $search = null)
|
public static function searchProfiles($start = 0, $count = 100, $search = null)
|
||||||
{
|
{
|
||||||
$publish = (DI::config()->get('system', 'publish_all') ? '' : "`publish` = 1");
|
$publish = (DI::config()->get('system', 'publish_all') ? 'true' : "`publish` = 1");
|
||||||
$total = 0;
|
$total = 0;
|
||||||
|
|
||||||
if (!empty($search)) {
|
if (!empty($search)) {
|
||||||
$searchTerm = '%' . $search . '%';
|
$searchTerm = '%' . $search . '%';
|
||||||
$cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total`
|
$cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total` FROM `owner-view`
|
||||||
FROM `profile`
|
WHERE $publish AND NOT `blocked` AND NOT `account_removed`
|
||||||
LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
|
AND ((`name` LIKE ?) OR
|
||||||
WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed`
|
(`nickname` LIKE ?) OR
|
||||||
AND ((`profile`.`name` LIKE ?) OR
|
(`about` LIKE ?) OR
|
||||||
(`user`.`nickname` LIKE ?) OR
|
(`locality` LIKE ?) OR
|
||||||
(`profile`.`about` LIKE ?) OR
|
(`region` LIKE ?) OR
|
||||||
(`profile`.`locality` LIKE ?) OR
|
(`country-name` LIKE ?) OR
|
||||||
(`profile`.`region` LIKE ?) OR
|
(`pub_keywords` LIKE ?) OR
|
||||||
(`profile`.`country-name` LIKE ?) OR
|
(`prv_keywords` LIKE ?))",
|
||||||
(`profile`.`pub_keywords` LIKE ?) OR
|
$searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm);
|
||||||
(`profile`.`prv_keywords` LIKE ?))",
|
|
||||||
$searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm,
|
|
||||||
$searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm);
|
|
||||||
} else {
|
} else {
|
||||||
$cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total`
|
$cnt = DBA::fetchFirst("SELECT COUNT(*) AS `total`
|
||||||
FROM `profile`
|
FROM `owner-view` WHERE $publish AND NOT `blocked` AND NOT `account_removed`");
|
||||||
LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
|
|
||||||
WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed`");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBA::isResult($cnt)) {
|
if (DBA::isResult($cnt)) {
|
||||||
|
@ -925,35 +920,23 @@ class Profile
|
||||||
if (!empty($search)) {
|
if (!empty($search)) {
|
||||||
$searchTerm = '%' . $search . '%';
|
$searchTerm = '%' . $search . '%';
|
||||||
|
|
||||||
$profiles = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
|
$profiles = DBA::p("SELECT * FROM `owner-view`
|
||||||
`contact`.`addr`, `contact`.`url` AS `profile_url`
|
WHERE $publish AND NOT `blocked` AND NOT `account_removed`
|
||||||
FROM `profile`
|
AND ((`name` LIKE ?) OR
|
||||||
LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
|
(`nickname` LIKE ?) OR
|
||||||
LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
|
(`about` LIKE ?) OR
|
||||||
WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self`
|
(`locality` LIKE ?) OR
|
||||||
AND ((`profile`.`name` LIKE ?) OR
|
(`region` LIKE ?) OR
|
||||||
(`user`.`nickname` LIKE ?) OR
|
(`country-name` LIKE ?) OR
|
||||||
(`profile`.`about` LIKE ?) OR
|
(`pub_keywords` LIKE ?) OR
|
||||||
(`profile`.`locality` LIKE ?) OR
|
(`prv_keywords` LIKE ?))
|
||||||
(`profile`.`region` LIKE ?) OR
|
$order LIMIT ?,?",
|
||||||
(`profile`.`country-name` LIKE ?) OR
|
|
||||||
(`profile`.`pub_keywords` LIKE ?) OR
|
|
||||||
(`profile`.`prv_keywords` LIKE ?))
|
|
||||||
$order LIMIT ?,?",
|
|
||||||
$searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm,
|
$searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm,
|
||||||
$searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm, $searchTerm,
|
|
||||||
$start, $count
|
$start, $count
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$profiles = DBA::p("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`, `user`.`timezone` , `user`.`page-flags`,
|
$profiles = DBA::p("SELECT * FROM `owner-view`
|
||||||
`contact`.`addr`, `contact`.`url` AS `profile_url`
|
WHERE $publish AND NOT `blocked` AND NOT `account_removed` $order LIMIT ?,?", $start, $count);
|
||||||
FROM `profile`
|
|
||||||
LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
|
|
||||||
LEFT JOIN `contact` ON `contact`.`uid` = `user`.`uid`
|
|
||||||
WHERE $publish AND NOT `user`.`blocked` AND NOT `user`.`account_removed` AND `contact`.`self`
|
|
||||||
$order LIMIT ?,?",
|
|
||||||
$start, $count
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,29 +140,26 @@ function vier_community_info()
|
||||||
|
|
||||||
// last 9 users
|
// last 9 users
|
||||||
if ($show_lastusers) {
|
if ($show_lastusers) {
|
||||||
$publish = (DI::config()->get('system', 'publish_all') ? '' : "`publish` = 1");
|
$condition = ['blocked' => false];
|
||||||
$order = " ORDER BY `register_date` DESC ";
|
if (!DI::config()->get('system', 'publish_all')) {
|
||||||
|
$condition['publish'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
$tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
|
$tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
|
||||||
|
|
||||||
$r = q("SELECT `profile`.*, `user`.`nickname`
|
$profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['register_date' => true], 'limit' => [0, 9]]);
|
||||||
FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
|
|
||||||
WHERE $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ",
|
|
||||||
0,
|
|
||||||
9
|
|
||||||
);
|
|
||||||
|
|
||||||
if (DBA::isResult($r)) {
|
if (DBA::isResult($profiles)) {
|
||||||
$aside['$lastusers_title'] = DI::l10n()->t('Last users');
|
$aside['$lastusers_title'] = DI::l10n()->t('Last users');
|
||||||
$aside['$lastusers_items'] = [];
|
$aside['$lastusers_items'] = [];
|
||||||
|
|
||||||
foreach ($r as $rr) {
|
foreach ($profiles as $profile) {
|
||||||
$profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['uid']);
|
$profile_link = 'profile/' . ((strlen($profile['nickname'])) ? $profile['nickname'] : $profile['uid']);
|
||||||
$entry = Renderer::replaceMacros($tpl, [
|
$entry = Renderer::replaceMacros($tpl, [
|
||||||
'$id' => $rr['id'],
|
'$id' => $profile['id'],
|
||||||
'$profile_link' => $profile_link,
|
'$profile_link' => $profile_link,
|
||||||
'$photo' => DI::baseUrl()->remove($rr['thumb']),
|
'$photo' => DI::baseUrl()->remove($profile['thumb']),
|
||||||
'$alt_text' => $rr['name']]);
|
'$alt_text' => $profile['name']]);
|
||||||
$aside['$lastusers_items'][] = $entry;
|
$aside['$lastusers_items'][] = $entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue