Fix unnecessary slices write
It seems that's the culprit for bad response time when sending big files.
This commit is contained in:
parent
58d1132ef6
commit
cd104cb512
|
@ -14,16 +14,20 @@ sub upload {
|
|||
my $c = shift;
|
||||
|
||||
$c->inactivity_timeout(30000000);
|
||||
$c->debug('Client connected');
|
||||
|
||||
$c->app->log->debug('Client connected');
|
||||
|
||||
$c->on(
|
||||
message => sub {
|
||||
my ($ws, $text) = @_;
|
||||
|
||||
my $begin = time;
|
||||
|
||||
my ($json) = split('XXMOJOXX', $text, 2);
|
||||
$json = encode 'UTF-8', $json;
|
||||
$json = decode_json $json;
|
||||
|
||||
$c->debug('Got message');
|
||||
$c->app->log->debug('Got message');
|
||||
|
||||
my $stop = 0;
|
||||
|
||||
|
@ -40,7 +44,7 @@ sub upload {
|
|||
}
|
||||
}
|
||||
# Check that we have enough space (multiplying by 2 since it's encrypted, it takes more place that the original file)
|
||||
elsif (($json->{size} * 2) >= dfportable('files')->{bavail}) {
|
||||
elsif ($json->{part} == 0 && ($json->{size} * 2) >= dfportable('files')->{bavail}) {
|
||||
$stop = 1;
|
||||
$c->send(sprintf('{"success": false, "msg":"'.$c->l('No enough space available on the server for this file (size: %1).', format_bytes($json->{size})).'", "sent_delay": %d, "i": %d}', $json->{delay}, $json->{i}));
|
||||
}
|
||||
|
@ -49,7 +53,7 @@ sub upload {
|
|||
my $f;
|
||||
if (defined($json->{id})) {
|
||||
my @records = LufiDB::Files->select('WHERE short = ?', $json->{id});
|
||||
$f = Lufi::File->new(record => $records[0]);
|
||||
$f = Lufi::File->new(record => $records[0]) if scalar @records;
|
||||
} else {
|
||||
my $delay;
|
||||
|
||||
|
@ -83,40 +87,46 @@ sub upload {
|
|||
$f->write;
|
||||
}
|
||||
|
||||
# If we already have a part, it's a resend because the websocket has been broken
|
||||
# In this case, we don't need to rewrite the file
|
||||
unless ($f->slices->grep(sub { $_->j == $json->{part} })->size) {
|
||||
# Create directory
|
||||
my $dir = catdir('files', $f->short);
|
||||
mkdir($dir, 0700) unless (-d $dir);
|
||||
# This check is just in case we didn't succeed to find a corresponding record
|
||||
# It normally can't happen
|
||||
if (defined $f) {
|
||||
# If we already have a part, it's a resend because the websocket has been broken
|
||||
# In this case, we don't need to rewrite the file
|
||||
unless ($f->slices->grep(sub { $_->j == $json->{part} })->size) {
|
||||
# Create directory
|
||||
my $dir = catdir('files', $f->short);
|
||||
mkdir($dir, 0700) unless (-d $dir);
|
||||
|
||||
# Create slice file
|
||||
my $file = catfile($dir, $json->{part}.'.part');
|
||||
my $s = Lufi::Slice->new(
|
||||
short => $f->short,
|
||||
j => $json->{part},
|
||||
path => $file
|
||||
);
|
||||
spurt $text, $file;
|
||||
push @{$f->slices}, $s;
|
||||
# Create slice file
|
||||
my $file = catfile($dir, $json->{part}.'.part');
|
||||
my $s = Lufi::Slice->new(
|
||||
short => $f->short,
|
||||
j => $json->{part},
|
||||
path => $file
|
||||
);
|
||||
spurt $text, $file;
|
||||
push @{$f->slices}, $s;
|
||||
$s->write;
|
||||
|
||||
if (($json->{part} + 1) == $json->{total}) {
|
||||
$f->complete(1);
|
||||
$f->created_at(time);
|
||||
if (($json->{part} + 1) == $json->{total}) {
|
||||
$f->complete(1);
|
||||
$f->created_at(time);
|
||||
$f->write;
|
||||
}
|
||||
}
|
||||
|
||||
$f->write;
|
||||
$c->provisioning;
|
||||
|
||||
$ws->send(sprintf('{"success": true, "i": %d, "j": %d, "parts": %d, "short": "%s", "name": "%s", "size": %d, "del_at_first_view": %s, "created_at": %d, "delay": %d, "token": "%s", "sent_delay": %d, "duration": %d}', $json->{i}, $json->{part}, $json->{total}, $f->short, $f->filename, $f->filesize, (($f->delete_at_first_view) ? 'true' : 'false'), $f->created_at, $f->delete_at_day, $f->mod_token, $json->{delay}, time - $begin));
|
||||
} else {
|
||||
$ws->send(sprintf('{"success": false, "msg":"'.$c->l('The server was unable to find the file record to add your file part to. Please, contact the administrator.').'", "sent_delay": %d, "i": %d}', $json->{delay}, $json->{i}));
|
||||
}
|
||||
|
||||
$c->provisioning;
|
||||
|
||||
$ws->send(sprintf('{"success": true, "i": %d, "j": %d, "parts": %d, "short": "%s", "name": "%s", "size": %d, "del_at_first_view": %s, "created_at": %d, "delay": %d, "token": "%s", "sent_delay": %d}', $json->{i}, $json->{part}, $json->{total}, $f->short, $f->filename, $f->filesize, (($f->delete_at_first_view) ? 'true' : 'false'), $f->created_at, $f->delete_at_day, $f->mod_token, $json->{delay}));
|
||||
}
|
||||
}
|
||||
);
|
||||
$c->on(
|
||||
finish => sub {
|
||||
$c->debug('Client disconnected');
|
||||
$c->app->log->debug('Client disconnected');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -126,7 +136,7 @@ sub download {
|
|||
my $short = $c->param('short');
|
||||
|
||||
$c->inactivity_timeout(300000);
|
||||
$c->debug('Client connected');
|
||||
$c->app->log->debug('Client connected');
|
||||
|
||||
my @records = LufiDB::Files->select('WHERE short = ?', $short);
|
||||
|
||||
|
@ -183,7 +193,7 @@ sub download {
|
|||
);
|
||||
$c->on(
|
||||
finish => sub {
|
||||
$c->debug('Client disconnected');
|
||||
$c->app->log->debug('Client disconnected');
|
||||
}
|
||||
);
|
||||
} else {
|
||||
|
|
|
@ -55,13 +55,6 @@ sub write {
|
|||
complete => $c->complete,
|
||||
);
|
||||
|
||||
$c->slices->each(
|
||||
sub {
|
||||
my ($e, $num) = @_;
|
||||
$e->write;
|
||||
}
|
||||
);
|
||||
|
||||
return $c;
|
||||
}
|
||||
|
||||
|
@ -98,9 +91,8 @@ sub _slurp {
|
|||
$c->complete($c->record->complete) if defined $c->record->complete;
|
||||
|
||||
my @slices = LufiDB::Slices->select('WHERE short = ? ORDER BY j ASC', $c->short);
|
||||
for my $s (@slices) {
|
||||
push @{$c->slices}, Lufi::Slice->new(record => $s);
|
||||
}
|
||||
|
||||
$c->slices(Mojo::Collection->new(map { Lufi::Slice->new(record => $_) } @slices));
|
||||
|
||||
return $c;
|
||||
}
|
||||
|
|
|
@ -65,11 +65,11 @@ msgstr ""
|
|||
msgid "Copy to clipboard"
|
||||
msgstr ""
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:288
|
||||
#: lib/Lufi/Controller/Files.pm:298
|
||||
msgid "Could not find the file. Are you sure of the URL and the token?"
|
||||
msgstr ""
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:216
|
||||
#: lib/Lufi/Controller/Files.pm:226
|
||||
msgid "Could not find the file. Are you sure of the URL?"
|
||||
msgstr ""
|
||||
|
||||
|
@ -121,15 +121,15 @@ msgstr ""
|
|||
msgid "Encrypting part XX1 of XX2"
|
||||
msgstr ""
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:152
|
||||
#: lib/Lufi/Controller/Files.pm:162
|
||||
msgid "Error: the file existed but has been deleted."
|
||||
msgstr ""
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:193
|
||||
#: lib/Lufi/Controller/Files.pm:203
|
||||
msgid "Error: the file has not been send entirely."
|
||||
msgstr ""
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:198
|
||||
#: lib/Lufi/Controller/Files.pm:208
|
||||
msgid "Error: unable to find the file. Are you sure of your URL?"
|
||||
msgstr ""
|
||||
|
||||
|
@ -145,7 +145,7 @@ msgstr ""
|
|||
msgid "Export localStorage data"
|
||||
msgstr ""
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:272
|
||||
#: lib/Lufi/Controller/Files.pm:282
|
||||
msgid "File deleted"
|
||||
msgstr ""
|
||||
|
||||
|
@ -222,7 +222,7 @@ msgid "My files"
|
|||
msgstr ""
|
||||
|
||||
#. (format_bytes($json->{size})
|
||||
#: lib/Lufi/Controller/Files.pm:45
|
||||
#: lib/Lufi/Controller/Files.pm:49
|
||||
msgid "No enough space available on the server for this file (size: %1)."
|
||||
msgstr ""
|
||||
|
||||
|
@ -280,7 +280,7 @@ msgstr ""
|
|||
msgid "Sorry, the uploading is currently disabled. Please try again later."
|
||||
msgstr ""
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:33
|
||||
#: lib/Lufi/Controller/Files.pm:37
|
||||
msgid "Sorry, uploading is disabled."
|
||||
msgstr ""
|
||||
|
||||
|
@ -300,7 +300,7 @@ msgstr ""
|
|||
msgid "The email subject can't be empty."
|
||||
msgstr ""
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:269
|
||||
#: lib/Lufi/Controller/Files.pm:279
|
||||
msgid "The file has already been deleted"
|
||||
msgstr ""
|
||||
|
||||
|
@ -322,17 +322,21 @@ msgstr ""
|
|||
msgid "The original (and only for now) author is <a href=\"https://fiat-tux.fr\" class=\"classic\">Luc Didry</a>. If you want to support him, you can to it via <a href=\"https://flattr.com/submit/auto?user_id=_SKy_&url=%1&title=Lufi&category=software\" class=\"classic\">Flattr</a> or with <a href=\"bitcoin:1CJYU2uGmPKhvithCGntyniTTe2hofpPX3?label=Lufi\" class=\"classic\">Bitcoin</a>."
|
||||
msgstr ""
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:122
|
||||
msgid "The server was unable to find the file record to add your file part to. Please, contact the administrator."
|
||||
msgstr ""
|
||||
|
||||
#: themes/default/templates/delays.html.ep:8
|
||||
msgid "This server sets limitations according to the file size. The expiration delay of your file will be the minimum between what you choose and the following limitations:"
|
||||
msgstr ""
|
||||
|
||||
#. ($short)
|
||||
#: lib/Lufi/Controller/Files.pm:253
|
||||
#: lib/Lufi/Controller/Files.pm:263
|
||||
msgid "Unable to get counter for %1. The file does not exists. It will be removed from your localStorage."
|
||||
msgstr ""
|
||||
|
||||
#. ($short)
|
||||
#: lib/Lufi/Controller/Files.pm:243
|
||||
#: lib/Lufi/Controller/Files.pm:253
|
||||
msgid "Unable to get counter for %1. The token is unvalid."
|
||||
msgstr ""
|
||||
|
||||
|
@ -381,7 +385,7 @@ msgid "You must give email addresses."
|
|||
msgstr ""
|
||||
|
||||
#. (format_bytes($json->{size})
|
||||
#: lib/Lufi/Controller/Files.pm:39
|
||||
#: lib/Lufi/Controller/Files.pm:43
|
||||
msgid "Your file is too big: %1 (maximum size allowed: %2)"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -71,11 +71,11 @@ msgstr "Copier tous les liens dans le presse-papier"
|
|||
msgid "Copy to clipboard"
|
||||
msgstr "Copier dans le presse-papier"
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:288
|
||||
#: lib/Lufi/Controller/Files.pm:298
|
||||
msgid "Could not find the file. Are you sure of the URL and the token?"
|
||||
msgstr "Impossible de retrouver le fichier. Êtes-vous sûr(e) que l’URL et le jeton sont les bons ?"
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:216
|
||||
#: lib/Lufi/Controller/Files.pm:226
|
||||
msgid "Could not find the file. Are you sure of the URL?"
|
||||
msgstr "Impossible de retrouver le fichier. Êtes-vous sûr(e) que l’URL est la bonne ?"
|
||||
|
||||
|
@ -127,15 +127,15 @@ msgstr "Mails"
|
|||
msgid "Encrypting part XX1 of XX2"
|
||||
msgstr "Chiffrement du fragment XX1 sur XX2"
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:152
|
||||
#: lib/Lufi/Controller/Files.pm:162
|
||||
msgid "Error: the file existed but has been deleted."
|
||||
msgstr "Erreur : le fichier existait mais a été supprimé"
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:193
|
||||
#: lib/Lufi/Controller/Files.pm:203
|
||||
msgid "Error: the file has not been send entirely."
|
||||
msgstr "Erreur : le fichier n’a pas été envoyé dans son intégralité"
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:198
|
||||
#: lib/Lufi/Controller/Files.pm:208
|
||||
msgid "Error: unable to find the file. Are you sure of your URL?"
|
||||
msgstr "Erreur : impossible de retrouver le fichier. Êtes-vous sûr(e) de l’URL ?"
|
||||
|
||||
|
@ -151,7 +151,7 @@ msgstr "Expire le"
|
|||
msgid "Export localStorage data"
|
||||
msgstr "Exporter les données localStorage"
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:272
|
||||
#: lib/Lufi/Controller/Files.pm:282
|
||||
msgid "File deleted"
|
||||
msgstr "Fichier supprimé"
|
||||
|
||||
|
@ -228,7 +228,7 @@ msgid "My files"
|
|||
msgstr "Mes fichiers"
|
||||
|
||||
#. (format_bytes($json->{size})
|
||||
#: lib/Lufi/Controller/Files.pm:45
|
||||
#: lib/Lufi/Controller/Files.pm:49
|
||||
msgid "No enough space available on the server for this file (size: %1)."
|
||||
msgstr "Espace disque insuffisant sur le serveur pour ce fichier (taille du fichier: %1)."
|
||||
|
||||
|
@ -290,7 +290,7 @@ msgstr "Partagez vos fichiers en toute confidentialité sur %1"
|
|||
msgid "Sorry, the uploading is currently disabled. Please try again later."
|
||||
msgstr "Désolé, l’envoi de fichier est actuellement désactivé. Veuillez réessayer plus tard."
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:33
|
||||
#: lib/Lufi/Controller/Files.pm:37
|
||||
msgid "Sorry, uploading is disabled."
|
||||
msgstr "Désolé, l’envoi de fichier est désactivé."
|
||||
|
||||
|
@ -310,7 +310,7 @@ msgstr "Le corps du mail ne peut être vide."
|
|||
msgid "The email subject can't be empty."
|
||||
msgstr "Le sujet du mail ne peut être vide."
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:269
|
||||
#: lib/Lufi/Controller/Files.pm:279
|
||||
msgid "The file has already been deleted"
|
||||
msgstr "Le fichier a déjà été supprimé"
|
||||
|
||||
|
@ -332,6 +332,10 @@ msgstr "Le mail a été envoyé."
|
|||
msgid "The original (and only for now) author is <a href=\"https://fiat-tux.fr\" class=\"classic\">Luc Didry</a>. If you want to support him, you can to it via <a href=\"https://flattr.com/submit/auto?user_id=_SKy_&url=%1&title=Lufi&category=software\" class=\"classic\">Flattr</a> or with <a href=\"bitcoin:1CJYU2uGmPKhvithCGntyniTTe2hofpPX3?label=Lufi\" class=\"classic\">Bitcoin</a>."
|
||||
msgstr "L’auteur originel (et pour l’instant, le seul) est <a href=\"https://fiat-tux.fr\" class=\"classic\">Luc Didry</a>. Si vous avez envie de le supporter, vous pouvez le faire via <a href=\"https://flattr.com/submit/auto?user_id=_SKy_&url=%1&title=Lufi&category=software\" class=\"classic\">Flattr</a> ou en <a href=\"bitcoin:1CJYU2uGmPKhvithCGntyniTTe2hofpPX3?label=Lufi\" class=\"classic\">Bitcoin</a>."
|
||||
|
||||
#: lib/Lufi/Controller/Files.pm:122
|
||||
msgid "The server was unable to find the file record to add your file part to. Please, contact the administrator."
|
||||
msgstr "Le serveur a été incapable de retrouver l’enregistrement du fichier auquel ajouter votre fragment de fichier. Veuillez contacter l'administrateur."
|
||||
|
||||
#: themes/default/templates/delays.html.ep:8
|
||||
msgid "This server sets limitations according to the file size. The expiration delay of your file will be the minimum between what you choose and the following limitations:"
|
||||
msgstr "Ce serveur impose des limitations selon la taille des fichiers. Le délai d’expiration de votre fichier sera le minimum entre ce que vous avez choisi et les limites suivantes :"
|
||||
|
@ -341,12 +345,12 @@ msgid "Unable to get counter for %1. The file does not exists."
|
|||
msgstr "Impossible de récupérer le compteur de %1. Le fichier n’existe pas."
|
||||
|
||||
#. ($short)
|
||||
#: lib/Lufi/Controller/Files.pm:253
|
||||
#: lib/Lufi/Controller/Files.pm:263
|
||||
msgid "Unable to get counter for %1. The file does not exists. It will be removed from your localStorage."
|
||||
msgstr "Impossible de récupérer le compteur pour %1. Le fichier n’existe pas. Il va être supprimé de votre localStorage."
|
||||
|
||||
#. ($short)
|
||||
#: lib/Lufi/Controller/Files.pm:243
|
||||
#: lib/Lufi/Controller/Files.pm:253
|
||||
msgid "Unable to get counter for %1. The token is unvalid."
|
||||
msgstr "Impossible de récupérer le compteur pour %1. Le jeton est invalide."
|
||||
|
||||
|
@ -395,7 +399,7 @@ msgid "You must give email addresses."
|
|||
msgstr "Vous devez envoyer des adresses mail."
|
||||
|
||||
#. (format_bytes($json->{size})
|
||||
#: lib/Lufi/Controller/Files.pm:39
|
||||
#: lib/Lufi/Controller/Files.pm:43
|
||||
msgid "Your file is too big: %1 (maximum size allowed: %2)"
|
||||
msgstr "Votre fichier est trop volumineux : %1 (la taille maximum autorisée est %2)"
|
||||
|
||||
|
|
|
@ -231,7 +231,7 @@ function updateProgressBar(data) {
|
|||
var short = data.short;
|
||||
var created_at = data.created_at;
|
||||
|
||||
console.log('getting response for slice '+(j + 1)+'/'+parts+' of file '+data.name);
|
||||
console.log('getting response for slice '+(j + 1)+'/'+parts+' of file '+data.name+' ('+data.duration+' sec)');
|
||||
|
||||
var dp = document.getElementById('progress-'+window.fc);
|
||||
var key = dp.getAttribute('data-key');
|
||||
|
|
Loading…
Reference in New Issue