Optimized DataTables state save handling performance

This commit is contained in:
Bernd Bestel 2023-09-01 17:04:11 +02:00
parent fdbb8a045a
commit 82d899d609
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 27 additions and 7 deletions

View File

@ -10,7 +10,8 @@
### Stock
- xxx
- Performance improvements related to the stock overview page / displaying a product card
- Performance improvements related to consuming products (thanks @alkuzman)
### Shopping list
@ -18,7 +19,7 @@
### Recipes
- Performance improvements when consuming recipes (thanks @alkuzman)
- xxx
### Meal plan
@ -50,7 +51,7 @@
### General
- xxx
- Performance improvements related to table (layout) loading handling
### API

View File

@ -20,14 +20,32 @@ $.extend(true, $.fn.dataTable.defaults, {
'stateSaveCallback': function(settings, data)
{
var settingKey = 'datatables_state_' + settings.sTableId;
if ($.isEmptyObject(data))
{
//state.clear was called and unfortunately the table is not refresh, so we are reloading the page
// state.clear() was called (resetting table layout)
Grocy.FrontendHelpers.DeleteUserSetting(settingKey, true);
} else
}
else
{
var stateData = JSON.stringify(data);
Grocy.FrontendHelpers.SaveUserSetting(settingKey, stateData);
// Don't save when the state data hasn't actually changed
if (Grocy.UserSettings[settingKey] !== undefined)
{
var data1 = JSON.parse(Grocy.UserSettings[settingKey]);
delete data1.time;
delete data1.childRows;
var data2 = Object.assign({}, data); // Clone `data` without reference
delete data2.time;
delete data2.childRows;
if (JSON.stringify(data1) == JSON.stringify(data2))
{
return;
}
}
Grocy.FrontendHelpers.SaveUserSetting(settingKey, JSON.stringify(data));
}
},
'stateLoadCallback': function(settings, data)
@ -277,6 +295,7 @@ $(".change-table-columns-visibility-button").on("click", function(e)
{
bootbox.confirm({
message: __t("Are you sure to reset the table options?"),
closeButton: false,
buttons: {
cancel: {
label: 'No',