Why delete is sending all the fields to the server instead of only the ID?
Why delete is sending all the fields to the server instead of only the ID?
Tester2017
Posts: 145Questions: 23Answers: 17
in Editor
What is the reason to send all the fields of a row to the server in case of a delete? Wouldn't it be more efficient to only send the ID's back?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
That's what Editor used to do, but there were a number of support requests for that behaviour to be added, so I did. Basically the main reason was to be able to log the data that has been deleted (exactly how is up to the developer). There were also some cases where dependent tables needed to be updated based on the deleted data, and that logic wasn't in the database.
I agree that generally this isn't needed - I'd typically just read back what is in the database anyway, but in terms of efficiency, it makes very little difference. There is a bit more overhead in the HTTP request, but I don't expect that to make any real difference to the performance. The Editor PHP libraries don't use that data - only the IDs, but its there if anyone needs them.
Allan
OK, I understand.
But yes I think there is some overhead if you are handling Ajax with $_POST in PHP. As you know PHP has the max_input_var limit (default 1,000). I will not change $_POST in JSON type calls and I will not be able to change the value of max_input_vars as I have a shared hosting plan. So when sending only the ID's back I would be able to delete 999 rows in 1 time. But if I am sending 20 fields per row I can only delete 49 rows per time.
But thanks for your answer.
You can use the
ajax.data
option to modify the data that is sent to the server. Either remove some of the fields, or more usefully have the function return the data as a JSON string - that way you can read from the input in your PHP script and send as many rows as you like (up to the max post size - not the max variables size).Allan
That's really great Allan! Thanks!.
@allan
For now, I resolved it this way:
I am posting this example as I lost a lot of time when I first tried to stringify 'd' which will give problems with decoding in PHP as stringify(d) returns not a string but an array.
And it could be shorter by using this:
And the final solution is only sending keys in case of a "remove" action:
Nice one - thanks for sharing this!
Allan