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

Destroy All Models At Once #4228

Open
jwogan5 opened this issue Nov 19, 2019 · 2 comments
Open

Destroy All Models At Once #4228

jwogan5 opened this issue Nov 19, 2019 · 2 comments

Comments

@jwogan5
Copy link

jwogan5 commented Nov 19, 2019

I know that backbone likes to call destroy on each model but in my particular case, it would be nice to be able to destroy all models in a collection with one call to speed up the process.

My scenario.
I am using Appcelerator which uses backbone collections to bind models to a list view. Say I have 100 models in the collection bound to the listview. This listview contains leads ( customers who made a call to a dealership in the past 30 days). Now I only want to show the customers who made calls to the dealer in the past 7 days. I could use reset but that does not remove the models so the current list would still show the 30-day list instead of the 7-day list. In order to show the 7-day list, I have to run a loop to destroy each model in the collection and re-populate the collection. The destroy loop for just 100 items takes about 10 seconds while adding the items takes under a second.

Without being able to remove all at once the UI since Appcelerator runs on the main thread is frozen until all the models are deleted. Currently, there is no workaround for this issue.

@jaapz
Copy link

jaapz commented Nov 20, 2019

Backbone adheres to how REST API's work. REST does not generally support DELETE on ranges or lists. That's why the Collection class does not have a destroy method. You'll have to build custom support for that yourself, if you really need it. However don't expect Backbone to ever support that.

I have to run a loop to destroy each model in the collection and re-populate the collection. The destroy loop for just 100 items takes about 10 seconds while adding the items takes under a second.

If you use a decent promise library and some smart looping you can do all or some of these HTTP calls "concurrently" and you won't have to wait for each of them to finish before starting another. That will probably speed up your the deletion process tremendously.

Note that I'm not a backbone maintainer but a maintainer will probably say the same.

@jgonggrijp
Copy link
Collaborator

I'm a Backbone maintainer (although only since recently) and in principle, I agree with what @jaapz wrote, though I also wonder: do you really need to destroy those models if you just want to see fewer of them? Besides, the destroy method is already non-blocking.

There's probably something I'm misunderstanding about the question. @jwogan5 please clarify whenever it suits you, I'll save this on ice in the meanwhile.

@jgonggrijp jgonggrijp added this to Fridge in Dusting off Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

3 participants