-
Notifications
You must be signed in to change notification settings - Fork 917
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
Refactor delete #3379
Refactor delete #3379
Conversation
Totally agree with all the decisions you've made here @martijnb92 - good work! It's definitely something we should do. I'll let @promatik or @pxpm pick this up to test it & review it, afterwards I'll hit merge. This new process where everything needs to be reviewed by one of them takes a little longer, but it lets fewer mistakes slip, so it's better in the long run 😄 Thanks again, cheers! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left comments in code.
Thanks again @martijnb92
// Remove the row from the datatable | ||
row.remove(); | ||
crud.table.row($("#crudTable a[data-route='"+route+"']").parents('tr')).remove().draw(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @martijnb92
Thanks again for one more contribution. I was testing this out, and I am afraid that this is a change we cannot aford to do.
Redrawing the table is a very expensive operation, if you want to have a better understanding of what I mean load 200 entries in the table and delete one, using both versions of code. (plus the cost of drawing the table goes up as the number of columns go up too not only the number of entries).
Let me know @martijnb92 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some testing with a table with 350 entries and 10 columns, never did it take more than a second to redraw the table, even on my phone.
The old version of the code is a bit faster/instant, since it only removes the table row. But that means the totale entries line at the top is incorrect, since it’s not updated on delete.
That’s why in my opinion the re-draw option in datatable is a good idea, since it actually removes the data instead of just removing the rendered table row.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarification on this.
Unfortunatelly we are aware of some issues in Datatables that make some tables take some amount of time to load. It's a combination of the number of columns, type of columns, number of entries etc, so I must sustain what I said before:
- the redraw option is only good in already fast tables, if you happen to have a table that takes 4 seconds to load, it will take 4 seconds to redraw (4 seconds it's not an HUGE issue in real big data cruds), but it will be 4 times faster to do it like previously than redrawing the table.
Let's keep in mind what you mentioned: the totale entries line at the top is incorrect, since it’s not updated on delete
, are you aware of someway we could update this value upon deletion or is redrawing the only option ?
Thanks for your effort in solving this, I am pretty sure we will end this with a better solution than what we have in current backpack code 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm good thinking... both of you 😂
- re-drawing the table is indeed more expensive;
- that number is wrong, so... this is a bug; a small one, but a bug nonetheless;
Tricky one...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok so... here's how I see it:
- Personally I don't see how we'd be able to redraw just that number, instead of redrawing the whole table. Not without breaking changes which are definitely not worth it.
- I don't think it's worth trying to just change the number at the top, because in some cases, the
count()
operation is the most expensive one (think tables with millions upon millions of entries - over there getting 10 entries is fast, counting 99 million entries is what's expensive). - Decrementing that number with JS... yeah... that feels like a hack so I'd rather we not do that either.
- Redrawing the datatable also prevents this one situation, that was annoying to me in the past: deleting a bunch of stuff one by one leads you to look at an empty table;
- Redrawing the datatable also fixes an inconsistency we currently have:
- Delete doesn't do a table redraw
- BulkDelete does do a datatable redraw;
(so if you use both Delete and BulkDelete, the not-redrawing thing looks like a bug, not a feature)
To me, it looks like the redraw is more expensive indeed, but it's a reasonable drawback for fixing this bug (and a few other minor bugs in the process).
I think the ones considerably affected by the redraw will be CRUDs paginated by 100+ items per page and/or with a large number of columns. But if redrawing is a problem there, it means it was also a problem at the first page load. And upon search. And upon filtering. And upon reordering. So it's a problem worth fixing.
I say... let's redraw 🥳 I'm still open to being convinced otherwise @pxpm if you feel strongly about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That being said, I did find a bug with redrawing the table. And I've noticed it's also a bug inside the BulkDelete operation, so we could fix it there too.
If you're on page 33/100, and you delete an item, you'd expect the item to be deleted but stay on page 33/100. But no, the way this PR redraws the table, the user is sent to page 1. Which I think will make it super-frustrating to users.
I've checked filters, they are kept.
I've checked search, that is kept.
But the page number is not, that is reset upon datatable redraw.
This is an awesome change, because this delete button content is merged once for every crud table entry. So as much we can shorten this file, the better. By my calculations, this small change can save around 14Kb/request (uncompressed) on a crud table with 20 entries/page. Thank you for this @martijnb92 🙌 |
// Remove the row from the datatable | ||
row.remove(); | ||
crud.table.row($("#crudTable a[data-route='"+route+"']").parents('tr')).remove().draw(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That being said, I did find a bug with redrawing the table. And I've noticed it's also a bug inside the BulkDelete operation, so we could fix it there too.
If you're on page 33/100, and you delete an item, you'd expect the item to be deleted but stay on page 33/100. But no, the way this PR redraws the table, the user is sent to page 1. Which I think will make it super-frustrating to users.
I've checked filters, they are kept.
I've checked search, that is kept.
But the page number is not, that is reset upon datatable redraw.
New commit to return the modal closing, totally missed it.. |
Excellent! Just tested this and it seems to me like all problems are fixed and it works great! Excellent job @martijnb92 . I'll let @promatik or @pxpm give it one more test, maybe they find something I didn't. But it looks like this is super-close to merging 🥳 |
The inspection completed: No new issues |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems good to me.
Thanks @martijnb92
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested with non responsive tables, and some edge cases, like having only one entry on the last page, and everything works as expected.
Thank you for another great improvement @martijnb92 🙌
Ooch.. I missed the show view.. Indeed |
Ugh! Thanks a lot for the heads-up @soufiene-slimi ! Fixed in #3404, merged and tagged. |
This PR fixes the following:
Removed (old?) call to close a modal. (I can't think of any modal that should be closed in the list view)