Skip to content

Commit a952a5f

Browse files
Merge pull request #4342 from corentin-soriano/speedup_keepass_import
Speedup keepass import by adding batch processing and sql transactions.
2 parents be46e4b + a20b659 commit a952a5f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

pages/import.js.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ function(data) {
495495
runtimes: "gears,html5,flash,silverlight,browserplus",
496496
browse_button: "import-keepass-attach-pickfile-keepass",
497497
container: "import-keepass-upload-zone",
498-
max_file_size: "10mb",
498+
max_file_size: "20mb",
499499
chunk_size: "0",
500500
unique_names: true,
501501
dragdrop: true,
@@ -731,7 +731,7 @@ function callRecurive(itemsList, foldersList, counter, itemsNumber) {
731731
data = {
732732
'edit-all': $('#import-keepass-edit-all-checkbox').prop('checked') === true ? 1 : 0,
733733
'edit-role': $('#import-keepass-edit-role-checkbox').prop('checked') === true ? 1 : 0,
734-
'items': itemsToAdd[0],
734+
'items': itemsToAdd.slice(0, 500),
735735
'folders': foldersList,
736736
}
737737
if (debugJavascript === true) {
@@ -771,7 +771,7 @@ function(data) {
771771
$('#import-feedback-result').append(data.info+"<br>");
772772

773773
// Remove item from list
774-
itemsToAdd.shift();
774+
itemsToAdd.splice(0, 500);
775775

776776
// Do recursive call until step = finished
777777
counter++

sources/import.queries.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -767,13 +767,17 @@ function handleGroups($groups, string $previousFolder, array $newItemsToAdd, int
767767
$receivedParameters['folders'],
768768
FILTER_SANITIZE_FULL_SPECIAL_CHARS
769769
);
770-
$item = filter_var_array(
770+
$post_items = filter_var_array(
771771
$receivedParameters['items'],
772772
FILTER_SANITIZE_FULL_SPECIAL_CHARS
773773
);
774774
$ret = '';
775775

776-
//foreach($post_items as $item) {
776+
// Start transaction for better performance
777+
DB::startTransaction();
778+
779+
// Import all items
780+
foreach($post_items as $item) {
777781
// get info about this folder
778782
$destinationFolderMore = DB::queryFirstRow(
779783
'SELECT title FROM '.prefixTable('nested_tree').' WHERE id = %i',
@@ -871,8 +875,10 @@ function handleGroups($groups, string $previousFolder, array $newItemsToAdd, int
871875

872876
// prepare return
873877
$ret .= "<li>".substr(stripslashes($item['Title']), 0, 500)." [".$destinationFolderMore['title']."]</li>";
874-
//}
878+
}
875879

880+
// Commit transaction.
881+
DB::commit();
876882

877883
echo prepareExchangedData(
878884
array(

0 commit comments

Comments
 (0)