mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
number format dashboard + improve scrape cache
This commit is contained in:
@@ -63,6 +63,7 @@ class TorrentBuyLogResource extends Resource
|
|||||||
->label(__('label.created_at'))
|
->label(__('label.created_at'))
|
||||||
,
|
,
|
||||||
])
|
])
|
||||||
|
->defaultSort('id','desc')
|
||||||
->filters([
|
->filters([
|
||||||
Tables\Filters\Filter::make('uid')
|
Tables\Filters\Filter::make('uid')
|
||||||
->form([
|
->form([
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ class DashboardRepository extends BaseRepository
|
|||||||
$result[$class] = [
|
$result[$class] = [
|
||||||
'name' => $class,
|
'name' => $class,
|
||||||
'text' => $value['text'],
|
'text' => $value['text'],
|
||||||
'value' => $userClasses->has($class) ? $userClasses->get($class) : 0,
|
'value' => $userClasses->has($class) ? number_format($userClasses->get($class)) : 0,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
@@ -124,55 +124,55 @@ class DashboardRepository extends BaseRepository
|
|||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.user.$name"),
|
'text' => nexus_trans("dashboard.user.$name"),
|
||||||
'value' => sprintf('%s / %s', User::query()->count(), Setting::get('main.maxusers')),
|
'value' => sprintf('%s / %s', number_format(User::query()->count()), number_format(Setting::get('main.maxusers'))),
|
||||||
];
|
];
|
||||||
$name = 'unconfirmed';
|
$name = 'unconfirmed';
|
||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.user.$name"),
|
'text' => nexus_trans("dashboard.user.$name"),
|
||||||
'value' => User::query()->where('status', User::STATUS_PENDING)->count(),
|
'value' => number_format(User::query()->where('status', User::STATUS_PENDING)->count()),
|
||||||
];
|
];
|
||||||
$name = 'visit_last_one_day';
|
$name = 'visit_last_one_day';
|
||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.user.$name"),
|
'text' => nexus_trans("dashboard.user.$name"),
|
||||||
'value' => User::query()->where('last_access', '>', $now->subDays(1))->count(),
|
'value' => number_format(User::query()->where('last_access', '>', $now->subDays(1))->count()),
|
||||||
];
|
];
|
||||||
$name = 'visit_last_one_week';
|
$name = 'visit_last_one_week';
|
||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.user.$name"),
|
'text' => nexus_trans("dashboard.user.$name"),
|
||||||
'value' => User::query()->where('last_access', '>', $now->subDays(7))->count(),
|
'value' => number_format(User::query()->where('last_access', '>', $now->subDays(7))->count()),
|
||||||
];
|
];
|
||||||
$name = 'visit_last_30_days';
|
$name = 'visit_last_30_days';
|
||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.user.$name"),
|
'text' => nexus_trans("dashboard.user.$name"),
|
||||||
'value' => User::query()->where('last_access', '>', $now->subDays(30))->count(),
|
'value' => number_format(User::query()->where('last_access', '>', $now->subDays(30))->count()),
|
||||||
];
|
];
|
||||||
$name = 'vip';
|
$name = 'vip';
|
||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.user.$name"),
|
'text' => nexus_trans("dashboard.user.$name"),
|
||||||
'value' => User::query()->where('class', User::CLASS_VIP)->count(),
|
'value' => number_format(User::query()->where('class', User::CLASS_VIP)->count()),
|
||||||
];
|
];
|
||||||
$name = 'donated';
|
$name = 'donated';
|
||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.user.$name"),
|
'text' => nexus_trans("dashboard.user.$name"),
|
||||||
'value' => User::query()->where('donor', 'yes')->count(),
|
'value' => number_format(User::query()->where('donor', 'yes')->count()),
|
||||||
];
|
];
|
||||||
$name = 'warned';
|
$name = 'warned';
|
||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.user.$name"),
|
'text' => nexus_trans("dashboard.user.$name"),
|
||||||
'value' => User::query()->where('warned', 'yes')->count(),
|
'value' => number_format(User::query()->where('warned', 'yes')->count()),
|
||||||
];
|
];
|
||||||
$name = 'disabled';
|
$name = 'disabled';
|
||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.user.$name"),
|
'text' => nexus_trans("dashboard.user.$name"),
|
||||||
'value' => User::query()->where('enabled', 'no')->count(),
|
'value' => number_format(User::query()->where('enabled', 'no')->count()),
|
||||||
];
|
];
|
||||||
|
|
||||||
$statGender = User::query()->groupBy('gender')->selectRaw('gender, count(*) as counts')->get()->pluck('counts','gender');
|
$statGender = User::query()->groupBy('gender')->selectRaw('gender, count(*) as counts')->get()->pluck('counts','gender');
|
||||||
@@ -184,7 +184,7 @@ class DashboardRepository extends BaseRepository
|
|||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.user.$name"),
|
'text' => nexus_trans("dashboard.user.$name"),
|
||||||
'value' => $statGender->has($gender) ? $statGender->get($gender) : 0,
|
'value' => $statGender->has($gender) ? number_format($statGender->get($gender)) : 0,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
@@ -197,13 +197,13 @@ class DashboardRepository extends BaseRepository
|
|||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.torrent.$name"),
|
'text' => nexus_trans("dashboard.torrent.$name"),
|
||||||
'value' => Torrent::query()->count(),
|
'value' => number_format(Torrent::query()->count()),
|
||||||
];
|
];
|
||||||
$name = 'dead';
|
$name = 'dead';
|
||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.torrent.$name"),
|
'text' => nexus_trans("dashboard.torrent.$name"),
|
||||||
'value' => Torrent::query()->where('visible', '=', Torrent::VISIBLE_NO)->count(),
|
'value' => number_format(Torrent::query()->where('visible', '=', Torrent::VISIBLE_NO)->count()),
|
||||||
];
|
];
|
||||||
|
|
||||||
$seeders = Peer::query()->where('seeder', 'yes')->count();
|
$seeders = Peer::query()->where('seeder', 'yes')->count();
|
||||||
@@ -211,7 +211,7 @@ class DashboardRepository extends BaseRepository
|
|||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.torrent.$name"),
|
'text' => nexus_trans("dashboard.torrent.$name"),
|
||||||
'value' => $seeders,
|
'value' => number_format($seeders),
|
||||||
];
|
];
|
||||||
|
|
||||||
$leechers = Peer::query()->where('seeder', 'no')->count();
|
$leechers = Peer::query()->where('seeder', 'no')->count();
|
||||||
@@ -219,13 +219,13 @@ class DashboardRepository extends BaseRepository
|
|||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.torrent.$name"),
|
'text' => nexus_trans("dashboard.torrent.$name"),
|
||||||
'value' => $leechers,
|
'value' => number_format($leechers),
|
||||||
];
|
];
|
||||||
$name = 'seeders_leechers';
|
$name = 'seeders_leechers';
|
||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.torrent.$name"),
|
'text' => nexus_trans("dashboard.torrent.$name"),
|
||||||
'value' => $seeders + $leechers,
|
'value' => number_format($seeders + $leechers),
|
||||||
];
|
];
|
||||||
$name = 'seeders_leechers_ratio';
|
$name = 'seeders_leechers_ratio';
|
||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
@@ -237,13 +237,13 @@ class DashboardRepository extends BaseRepository
|
|||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.torrent.$name"),
|
'text' => nexus_trans("dashboard.torrent.$name"),
|
||||||
'value' => User::query()->where('last_access', '>', $now->subSeconds(900))->count(),
|
'value' => number_format(User::query()->where('last_access', '>', $now->subSeconds(900))->count()),
|
||||||
];
|
];
|
||||||
$name = 'active_tracker_users';
|
$name = 'active_tracker_users';
|
||||||
$result[$name] = [
|
$result[$name] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'text' => nexus_trans("dashboard.torrent.$name"),
|
'text' => nexus_trans("dashboard.torrent.$name"),
|
||||||
'value' => Peer::query()->selectRaw('count(distinct(userid)) as counts')->first()->counts,
|
'value' => number_format(Peer::query()->selectRaw('count(distinct(userid)) as counts')->first()->counts),
|
||||||
];
|
];
|
||||||
|
|
||||||
$name = 'total_torrent_size';
|
$name = 'total_torrent_size';
|
||||||
@@ -281,12 +281,12 @@ class DashboardRepository extends BaseRepository
|
|||||||
|
|
||||||
public function latestUser()
|
public function latestUser()
|
||||||
{
|
{
|
||||||
return User::query()->orderBy('id', 'desc')->limit(10)->select(User::$commonFields)->get();
|
return User::query()->orderBy('id', 'desc')->limit(10)->get(User::$commonFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function latestTorrent()
|
public function latestTorrent()
|
||||||
{
|
{
|
||||||
return Torrent::query()->with(['user'])->orderBy('id', 'desc')->limit(5)->get();
|
return Torrent::query()->with(['user'])->orderBy('id', 'desc')->limit(5)->get(Torrent::$commentFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
|
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
|
||||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-03-04');
|
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-03-05');
|
||||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||||
|
|||||||
@@ -45,10 +45,10 @@ function block_browser()
|
|||||||
|
|
||||||
function benc_resp($d)
|
function benc_resp($d)
|
||||||
{
|
{
|
||||||
|
do_log(nexus_json_encode($d));
|
||||||
benc_resp_raw(\Rhilip\Bencode\Bencode::encode($d));
|
benc_resp_raw(\Rhilip\Bencode\Bencode::encode($d));
|
||||||
}
|
}
|
||||||
function benc_resp_raw($x) {
|
function benc_resp_raw($x) {
|
||||||
do_log($x);
|
|
||||||
header("Content-Type: text/plain; charset=utf-8");
|
header("Content-Type: text/plain; charset=utf-8");
|
||||||
header("Pragma: no-cache");
|
header("Pragma: no-cache");
|
||||||
|
|
||||||
|
|||||||
+8
-8
@@ -7,14 +7,6 @@ dbconn_announce();
|
|||||||
// BLOCK ACCESS WITH WEB BROWSERS AND CHEATS!
|
// BLOCK ACCESS WITH WEB BROWSERS AND CHEATS!
|
||||||
block_browser();
|
block_browser();
|
||||||
|
|
||||||
$cacheKey = md5($_SERVER["QUERY_STRING"]);
|
|
||||||
$cacheData = \Nexus\Database\NexusDB::cache_get($cacheKey);
|
|
||||||
if ($cacheData) {
|
|
||||||
do_log("[SCRAPE_FROM_CACHE]: " . $_SERVER["QUERY_STRING"]);
|
|
||||||
benc_resp($cacheData);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
preg_match_all('/info_hash=([^&]*)/i', $_SERVER["QUERY_STRING"], $info_hash_array);
|
preg_match_all('/info_hash=([^&]*)/i', $_SERVER["QUERY_STRING"], $info_hash_array);
|
||||||
$fields = "info_hash, times_completed, seeders, leechers";
|
$fields = "info_hash, times_completed, seeders, leechers";
|
||||||
|
|
||||||
@@ -26,6 +18,14 @@ else {
|
|||||||
$query = "SELECT $fields FROM torrents WHERE " . hash_where_arr('info_hash', $info_hash_array[1]);
|
$query = "SELECT $fields FROM torrents WHERE " . hash_where_arr('info_hash', $info_hash_array[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$cacheKey = md5(http_build_query($info_hash_array[1]));
|
||||||
|
$cacheData = \Nexus\Database\NexusDB::cache_get($cacheKey);
|
||||||
|
if ($cacheData) {
|
||||||
|
do_log("[SCRAPE_FROM_CACHE]: " . $_SERVER["QUERY_STRING"]);
|
||||||
|
benc_resp($cacheData);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
$res = sql_query($query);
|
$res = sql_query($query);
|
||||||
|
|
||||||
if (mysql_num_rows($res) < 1){
|
if (mysql_num_rows($res) < 1){
|
||||||
|
|||||||
Reference in New Issue
Block a user