1
0
mirror of https://github.com/torrentpier/torrentpier.git synced 2025-03-12 04:35:42 -07:00

Make caching for ban list ()

This commit is contained in:
Roman Kelesidis 2023-12-27 00:16:54 +07:00 committed by GitHub
parent ed34bbb735
commit 66083cabad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 31 deletions

@ -67,6 +67,7 @@ if (isset($_POST['submit'])) {
}
}
$datastore->update('ban_list');
bb_die($lang['BAN_UPDATE_SUCESSFUL'] . '<br /><br />' . sprintf($lang['CLICK_RETURN_BANADMIN'], '<a href="admin_user_ban.php">', '</a>') . '<br /><br />' . sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>'));
} else {
$template->assign_vars(['S_BANLIST_ACTION' => 'admin_user_ban.php']);

@ -0,0 +1,21 @@
<?php
/**
* TorrentPier Bull-powered BitTorrent tracker engine
*
* @copyright Copyright (c) 2005-2024 TorrentPier (https://torrentpier.com)
* @link https://github.com/torrentpier/torrentpier for the canonical source repository
* @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License
*/
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
}
$sql = "SELECT * FROM " . BB_BANLIST;
$bans = [];
foreach (DB()->fetch_rowset($sql) as $row) {
$bans[$row['ban_userid']] = $row;
}
$this->store('ban_list', $bans);

@ -11,9 +11,8 @@ if (!defined('BB_ROOT')) {
die(basename(__FILE__));
}
$ranks = [];
$sql = "SELECT * FROM " . BB_RANKS;
$ranks = [];
foreach (DB()->fetch_rowset($sql) as $row) {
$ranks[$row['rank_id']] = $row;

@ -2183,15 +2183,13 @@ function user_birthday_icon($user_birthday, $user_id): string
*/
function getUserBanInfo(int $userId): ?array
{
return DB()->fetch_row("SELECT * FROM " . BB_BANLIST . " WHERE ban_userid = $userId LIMIT 1");
}
global $datastore;
/**
* Returns information about all bans
*
* @return array|null
*/
function getAllBans(): ?array
{
return DB()->fetch_rowset("SELECT * FROM " . BB_BANLIST);
// Get bans info from datastore
if (!$bans = $datastore->get('ban_list')) {
$datastore->update('ban_list');
$bans = $datastore->get('ban_list');
}
return $bans[$userId] ?? [];
}

@ -394,20 +394,6 @@ $user = new TorrentPier\Legacy\Common\User();
$userdata =& $user->data;
/**
* Initial ban check
*/
if ($banInfo = getUserBanInfo((int)$user->id)) {
if (!IS_GUEST) {
$user->session_end();
}
if (!empty($banInfo['ban_reason'])) {
bb_die($lang['YOU_BEEN_BANNED'] . '<br><br>' . $banInfo['ban_reason']);
} else {
bb_die($lang['YOU_BEEN_BANNED']);
}
}
/**
* Cron
*/

@ -108,7 +108,7 @@ class User
*/
public function session_start(array $cfg = [])
{
global $bb_cfg;
global $bb_cfg, $lang;
$update_sessions_table = false;
$this->cfg = array_merge($this->cfg, $cfg);
@ -217,26 +217,35 @@ class User
$this->init_userprefs();
// Initial ban check
if ($banInfo = getUserBanInfo((int)$this->id)) {
if (!empty($banInfo['ban_reason'])) {
bb_die($lang['YOU_BEEN_BANNED'] . '<br><br>' . $banInfo['ban_reason']);
} else {
bb_die($lang['YOU_BEEN_BANNED']);
}
$this->session_end();
}
return $this->data;
}
/**
* Create new session for the given user
*
* @param $userdata
* @param array $userdata
* @param bool $auto_created
*
* @return array
*/
public function session_create($userdata, bool $auto_created = false): array
public function session_create(array $userdata, bool $auto_created = false): array
{
global $bb_cfg, $lang;
global $bb_cfg;
$this->data = $userdata;
$session_id = $this->sessiondata['sid'];
$login = ((int)$this->data['user_id'] !== GUEST_UID);
$is_user = ((int)$this->data['user_level'] !== ADMIN);
$user_id = (int)$this->data['user_id'];
$mod_admin_session = ((int)$this->data['user_level'] === ADMIN || (int)$this->data['user_level'] === MOD);

@ -47,6 +47,7 @@ class Common
'moderators' => 'build_moderators.php',
'stats' => 'build_stats.php',
'ranks' => 'build_ranks.php',
'ban_list' => 'build_bans.php',
'attach_extensions' => 'build_attach_extensions.php',
'smile_replacements' => 'build_smilies.php',
];