improve get_user_row()

This commit is contained in:
xiaomlove
2022-08-23 01:02:54 +08:00
parent efec6348ef
commit 8217402643
2 changed files with 18 additions and 13 deletions
+15 -12
View File
@@ -705,22 +705,25 @@ function get_user_row($id)
{ {
global $Cache, $CURUSER; global $Cache, $CURUSER;
static $curuserRowUpdated = false; static $curuserRowUpdated = false;
static $neededColumns = array('id', 'noad', 'class', 'enabled', 'privacy', 'avatar', 'signature', 'uploaded', 'downloaded', 'last_access', 'username', 'donor', 'donoruntil', 'leechwarn', 'warned', 'title'); static $neededColumns = array(
'id', 'noad', 'class', 'enabled', 'privacy', 'avatar', 'signature', 'uploaded', 'downloaded', 'last_access', 'username', 'donor',
'donoruntil', 'leechwarn', 'warned', 'title', 'downloadpos', 'parked', 'clientselect', 'showclienterror',
);
$cacheKey = 'user_'.$id.'_content'; $cacheKey = 'user_'.$id.'_content';
$row = \Nexus\Database\NexusDB::remember($cacheKey, 900, function () use ($id, $neededColumns) { $row = \Nexus\Database\NexusDB::remember($cacheKey, 900, function () use ($id, $neededColumns) {
$user = \App\Models\User::query()->with(['wearing_medals'])->find($id, $neededColumns); $user = \App\Models\User::query()->with(['wearing_medals'])->find($id, $neededColumns);
if ($user) { if (!$user) {
$userRep = new \App\Repositories\UserRepository(); return null;
$metas = $userRep->listMetas($id, \App\Models\UserMeta::META_KEY_PERSONALIZED_USERNAME);
$arr = $user->toArray();
if ($metas->isNotEmpty()) {
$arr['__is_rainbow'] = 1;
} else {
$arr['__is_rainbow'] = 0;
}
return $arr;
} }
return null; $arr = $user->toArray();
$userRep = new \App\Repositories\UserRepository();
$metas = $userRep->listMetas($id, \App\Models\UserMeta::META_KEY_PERSONALIZED_USERNAME);
if ($metas->isNotEmpty()) {
$arr['__is_rainbow'] = 1;
} else {
$arr['__is_rainbow'] = 0;
}
return $arr;
}); });
// if ($CURUSER && $id == $CURUSER['id']) { // if ($CURUSER && $id == $CURUSER['id']) {
+3 -1
View File
@@ -172,7 +172,9 @@ if (!$torrent) {
do_log("[TORRENT NOT EXISTS] infoHashUrlEncode: $infoHashUrlEncode", 'error'); do_log("[TORRENT NOT EXISTS] infoHashUrlEncode: $infoHashUrlEncode", 'error');
err("torrent not registered with this tracker"); err("torrent not registered with this tracker");
} elseif (!user_can('seebanned', false, $userid)) { }
//Do not use user_can(), some func user_can() used is not available IN_TRACKER
if ($az['class'] < $seebanned_class) {
if ($torrent['banned'] == 'yes') { if ($torrent['banned'] == 'yes') {
err("torrent banned"); err("torrent banned");
} elseif ($torrent['approval_status'] != \App\Models\Torrent::APPROVAL_STATUS_ALLOW && get_setting('torrent.approval_status_none_visible') == 'no') { } elseif ($torrent['approval_status'] != \App\Models\Torrent::APPROVAL_STATUS_ALLOW && get_setting('torrent.approval_status_none_visible') == 'no') {