Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup copy/delete folder and copy item actions. #4343

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pages/items.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,11 @@ function(data) {
timeOut: 1000
}
);

// Select folder of new item in jstree
$('#jstree').jstree('deselect_all');
$('#jstree').jstree('select_node', '#li_' + $('#form-item-copy-destination').val());

// Refresh tree
refreshTree(parseInt($('#form-item-copy-destination').val()), true);
// Load list of items
Expand All @@ -1611,7 +1616,7 @@ function(data) {
);

// Close
$('#folder-tree-container').removeClass('hidden');
$('#folders-tree-card').removeClass('hidden');
$('.form-item-copy').addClass('hidden');
} else {
// ERROR
Expand Down Expand Up @@ -3220,6 +3225,11 @@ function(data) {
key: '<?php echo $session->get('key'); ?>'
}
);

// Select new folder of item in jstree
$('#jstree').jstree('deselect_all');
$('#jstree').jstree('select_node', '#li_' + $('#form-item-folder').val());

} else if ($('#form-item-button-save').data('action') === 'new_item') {
window.location.href = './index.php?page=items&group='+$('#form-item-folder').val()+'&id='+data.item_id;
return;
Expand Down
66 changes: 8 additions & 58 deletions sources/folders.queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@
'id = %i',
$item['id']
);

// log
logItems(
$SETTINGS,
Expand All @@ -772,51 +772,6 @@

//Update CACHE table
updateCacheTable('delete_value',(int) $item['id']);
/*
// --> build json tree
// update cache_tree
$cache_tree = DB::queryfirstrow(
'SELECT increment_id, folders, visible_folders
FROM ' . prefixTable('cache_tree').' WHERE user_id = %i',
(int) $session->get('user-id')
);
if (DB::count()>0) {
// remove id from folders
if (empty($cache_tree['folders']) === false && is_null($cache_tree['folders']) === false) {
$a_folders = json_decode($cache_tree['folders'], true);
$key = array_search($item['id'], $a_folders, true);
if ($key !== false) {
unset($a_folders[$key]);
}
} else {
$a_folders = [];
}
// remove id from visible_folders
if (empty($cache_tree['visible_folders']) === false && is_null($cache_tree['visible_folders']) === false) {
$a_visible_folders = json_decode($cache_tree['visible_folders'], true);
foreach ($a_visible_folders as $i => $v) {
if ($v['id'] == $item['id']) {
unset($a_visible_folders[$i]);
}
}
} else {
$a_visible_folders = [];
}
DB::update(
prefixTable('cache_tree'),
array(
'folders' => json_encode($a_folders),
'visible_folders' => json_encode($a_visible_folders),
'timestamp' => time(),
),
'increment_id = %i',
(int) $cache_tree['increment_id']
);
}
// <-- end - build json tree
*/
}

//Actualize the variable
Expand All @@ -825,7 +780,7 @@
}
}
}

// Add new task for building user cache tree
if ((int) $session->get('user-admin') !== 1) {
DB::insert(
Expand All @@ -848,7 +803,7 @@
foreach ($folderForDel as $fol) {
DB::delete(prefixTable('nested_tree'), 'id = %i', $fol);
}

// Update timestamp
DB::update(
prefixTable('misc'),
Expand All @@ -860,16 +815,12 @@
'timestamp',
'last_folder_change'
);

// Commit transaction
DB::commit();

//rebuild tree
$tree->rebuild();

// reload cache table
include_once $SETTINGS['cpassman_dir'] . '/sources/main.functions.php';
updateCacheTable('reload', null);

echo prepareExchangedData(
array(
Expand Down Expand Up @@ -1348,17 +1299,16 @@
'at_copy',
$session->get('user-login')
);

// Add item to cache table
updateCacheTable('add_value', (int) $newItemId);
}
}
}

// rebuild tree
$tree->rebuild();

// reload cache table
include_once $SETTINGS['cpassman_dir'] . '/sources/main.functions.php';
updateCacheTable('reload', NULL);

// Update timestamp
DB::update(
prefixTable('misc'),
Expand Down
6 changes: 3 additions & 3 deletions sources/items.queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -2469,9 +2469,6 @@
'at_copy',
$session->get('user-login')
);
// reload cache table
include_once $SETTINGS['cpassman_dir'] . '/sources/main.functions.php';
updateCacheTable('reload', null);

echo (string) prepareExchangedData(
array(
Expand All @@ -2481,6 +2478,9 @@
),
'encode'
);

// Add new item to cache table.
updateCacheTable('add_value', (int) $newItemId);
} else {
// no item
echo (string) prepareExchangedData(
Expand Down