Deleting select rows from a table

I use Anvil tables for temporary storage sometimes, I use them to hold a subset of table rows that the user might be editing, then I submit that collection for further processing, etc.

When I initiate a form/session, I pull the records in a table that have the user’s email as the ‘owner’ (sometimes using writable table views).

When I clear out this temp storage, either on the server or the client, I get the collection and iterate over the rows with row.delete()

I’m aware of tables.delete_all_rows() - which is so much faster

is there a way to return a subset of rows based on search criteria, and then delete that entire subset in one fell swoop? Iterating over each row in a collection, even a subset, sometimes has me staring at the spinner.

It’d be nice if delete_all_rows() worked on a client-writeable view (or maybe a search iterator, if done in the server). I’ve never found any better way than iterating and deleting individually.

I can’t even think of way to speed it up - I think I need to start working in the front end with a list of dicts, or a dict, something. All the round trips to the server and/or iterating over all the rows puts you in SpinnerHell

I belive you implied this, but all interation over datatable rows is much faster on the server side.

In any case, I wonder if you could write up a little background task/function that periodically checks a table for rows to be deleted. Just something that comes to mind.

Probably a good FR here though it seems.

I’ll definitely move the iteration to the server side, as you say that will likely speed things up significantly

I created a feature request for the ability to delete a set of rows more efficiently. Like it to show support: Delete set of rows from data table more efficiently

5 Likes