mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-22 10:08:31 -05:00
update: inline client stats query
The query only takes 6 seconds on my local untuned machine. Caching it for an hour is probably fine, we have worse queries out there, and indexing isn't an option since this table is write-heavy. Reduces overall complexity and prevents blank page after cache is reset.
This commit is contained in:
@@ -305,7 +305,22 @@ class StatsController extends Controller
|
||||
*/
|
||||
public function clients(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
{
|
||||
$clients = cache()->get('stats:clients') ?? [];
|
||||
$clients = cache()->remember(
|
||||
'stats:clients',
|
||||
3600,
|
||||
fn () => Peer::selectRaw('agent, COUNT(*) as user_count, SUM(peer_count) as peer_count')
|
||||
->fromSub(
|
||||
Peer::query()
|
||||
->select(['agent', 'user_id', DB::raw('COUNT(*) as peer_count')])
|
||||
->groupBy('agent', 'user_id')
|
||||
->where('active', '=', true),
|
||||
'distinct_agent_user'
|
||||
)
|
||||
->groupBy('agent')
|
||||
->orderBy('agent')
|
||||
->get()
|
||||
->toArray()
|
||||
);
|
||||
|
||||
$groupedClients = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user