Skip to content

Commit

Permalink
Display project size in human friendly format (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-suse authored Jul 29, 2024
1 parent c1a0522 commit 77768b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
20 changes: 19 additions & 1 deletion assets/javascripts/admintable.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,24 @@ function renderAdminReadonly(data, type, row, meta) {
return data ? data : '';
}

function renderAdminSize(data, type, row, meta) {
if(type === 'display' && data) {
if (Math.abs(data) < 1024) {
return data;
}
const units = ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let u = -1;

do {
data /= 1024;
++u;
} while (Math.round(Math.abs(data) * 10) >= 1024 && u < units.length - 1);

return data.toFixed(1) + ' ' + units[u];
}
return data ? data : '';
}

function renderAdminTableSettingsList(data, type, row, meta) {
var plainText = type !== 'display';
var edit = isEditingAdminTableRow(meta);
Expand Down Expand Up @@ -442,7 +460,7 @@ function setupAdminTable(editable) {
}
emptyRow[columnName] = "";
} else if (th.hasClass('col_ro')) {
columnDef.render = renderAdminReadonly;
columnDef.render = (columnName == 'size'? renderAdminSize : renderAdminReadonly);
emptyRow.settings = {};
} else if (th.hasClass('col_unixtime')) {
columnDef.render = renderAdminUnixtime;
Expand Down
3 changes: 0 additions & 3 deletions lib/MirrorCache/Task/ReportProjectSize.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ sub _run {
return $job->finish('Previous report job is still active for ' . $path)
unless my $guard = $minion->guard('report_project_size_' . $path, 30*60);

my $realpath = $app->mc->root->rootpath($path);
return $job->fail('Path not found: ' . $path) unless $realpath;

my ($size, $file_cnt, $lm) = $app->schema->resultset('Folder')->calculate_disk_usage($path);

$job->note("total size" => $size, "file count" => $file_cnt, "last modified" => $lm);
Expand Down
6 changes: 1 addition & 5 deletions lib/MirrorCache/WebAPI/Plugin/Backstage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sub new {
}

my @permanent_jobs =
qw(folder_sync_schedule_from_misses folder_sync_schedule mirror_scan_schedule_from_misses mirror_scan_schedule_from_path_errors mirror_scan_schedule project_sync_schedule cleanup stat_agg_schedule mirror_check_from_stat report);
qw(folder_sync_schedule_from_misses folder_sync_schedule mirror_scan_schedule_from_misses mirror_scan_schedule_from_path_errors mirror_scan_schedule project_sync_schedule cleanup stat_agg_schedule mirror_check_from_stat report report_project_size_schedule);

sub register_tasks {
my $self = shift;
Expand All @@ -46,10 +46,6 @@ sub register_tasks {
if ($app->mcconfig->mirror_provider) {
push @permanent_jobs, 'mirror_provider_sync';
}
eval {
my $projects = $app->mcproject->list;
push @permanent_jobs, 'report_project_size_schedule' if @$projects;
};

$app->plugin($_)
for (
Expand Down

0 comments on commit 77768b7

Please sign in to comment.