mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-04 15:26:43 +02:00
feat(admin): add instance wide dashboard with storage and bandwidth usage
* add DashboardCard component * add instance wide podcasts and episodes numbers * add app.storageLimit environment variable * divide bytes by 1000 instead of 1024 in stats sql queries closes #216
This commit is contained in:
parent
3d363f2efe
commit
b1a6c02e56
57 changed files with 394 additions and 139 deletions
|
|
@ -12,6 +12,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Analytics\Models;
|
||||
|
||||
use App\Entities\Media\BaseMedia;
|
||||
use App\Models\MediaModel;
|
||||
use CodeIgniter\Model;
|
||||
use Modules\Analytics\Entities\AnalyticsPodcasts;
|
||||
|
||||
|
|
@ -93,7 +95,7 @@ class AnalyticsPodcastModel extends Model
|
|||
public function getDataBandwidthByDay(int $podcastId): array
|
||||
{
|
||||
if (! ($found = cache("{$podcastId}_analytics_podcast_by_bandwidth"))) {
|
||||
$found = $this->select('date as labels, round(bandwidth / 1048576, 1) as `values`')
|
||||
$found = $this->select('date as labels, ROUND(bandwidth / 1000000, 2) as `values`')
|
||||
->where([
|
||||
'podcast_id' => $podcastId,
|
||||
'date >' => date('Y-m-d', strtotime('-60 days')),
|
||||
|
|
@ -235,4 +237,48 @@ class AnalyticsPodcastModel extends Model
|
|||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets total bandwidth data for instance
|
||||
*
|
||||
* @return AnalyticsPodcasts[]
|
||||
*/
|
||||
public function getDataTotalBandwidthByMonth(): array
|
||||
{
|
||||
if (! ($found = cache('analytics_total_bandwidth_by_month'))) {
|
||||
$found = $this->select(
|
||||
'DATE_FORMAT(updated_at,"%Y-%m") as labels, ROUND(sum(bandwidth) / 1000000, 2) as `values`'
|
||||
)
|
||||
->groupBy('labels')
|
||||
->orderBy('labels', 'ASC')
|
||||
->findAll();
|
||||
|
||||
cache()
|
||||
->save('analytics_total_bandwidth_by_month', $found, 600);
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total storage
|
||||
*
|
||||
* @return BaseMedia[]
|
||||
*/
|
||||
public function getDataTotalStorageByMonth(): array
|
||||
{
|
||||
if (! ($found = cache('analytics_total_storage_by_month'))) {
|
||||
$found = (new MediaModel())->select(
|
||||
'DATE_FORMAT(uploaded_at,"%Y-%m") as labels, ROUND(sum(file_size) / 1000000, 2) as `values`'
|
||||
)
|
||||
->groupBy('labels')
|
||||
->orderBy('labels', 'ASC')
|
||||
->findAll();
|
||||
|
||||
cache()
|
||||
->save('analytics_total_storage_by_month', $found, 600);
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue