The API call for fetching a tasklog with limit=0 now returns the whole
log as a file stream rather than reading all lines in memory and then
transfering them in JSON format. The behaviour when the url parameter
limit is undefined or not 0 is the same as before, in accordance
with the API specification.

Signed-off-by: Daniel Tschlatscher <d.tschlatsc...@proxmox.com>
---
 PVE/API2/Tasks.pm | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/PVE/API2/Tasks.pm b/PVE/API2/Tasks.pm
index 9cd1e56b..88762f2f 100644
--- a/PVE/API2/Tasks.pm
+++ b/PVE/API2/Tasks.pm
@@ -5,6 +5,7 @@ use warnings;
 use POSIX;
 use IO::File;
 use File::ReadBackwards;
+use File::stat;
 use PVE::Tools;
 use PVE::SafeSyslog;
 use PVE::RESTHandler;
@@ -387,11 +388,17 @@ __PACKAGE__->register_method({
            $rpcenv->check($user, "/nodes/$node", [ 'Sys.Audit' ]);
        }
 
-       my ($count, $lines) = PVE::Tools::dump_logfile($filename, $start, 
$limit);
+       if ($limit == 0) {
+           # TCP Max Transfer Unit size is 1500, compression for lower numbers 
has no effect
+           my $use_compression = stat($filename)->size > 1500;
+           return PVE::Tools::stream_file($filename, $param->{upid}, 
$use_compression);
+       } else {
+           my ($count, $lines) = PVE::Tools::dump_logfile($filename, $start, 
$limit);
 
-       $rpcenv->set_result_attrib('total', $count);
+           $rpcenv->set_result_attrib('total', $count);
 
-       return $lines;
+           return $lines;
+       }
     }});
 
 
-- 
2.30.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to