question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

☂️ Moving towards fast deletes

See original GitHub issue

This is to fix: https://github.com/Nozbe/WatermelonDB/issues/186

Right now, deleting records is not very efficient in WatermelonDB.

Say you have models like this: Blog has_many Post has_many Comment. If you want to delete a blog post, you also have to delete all its posts, and all their comments. This happens one-by-one currently. What we need is the ability to efficiently (and atomically if possible) delete the whole tree in one go.

This needs some work and we need Community help (your help!) to achieve this:

  • Step 1: Implement prepareMarkAsDelete / prepareDestroyPermanently on batch - https://github.com/Nozbe/WatermelonDB/pull/294
  • Step 2: Implement Model.experimental_markAsDelete() / Model.experimental_destroyPermanently(), which will iterate over model’s associations and for each belongs_to relationship, for each of them fetch() record’s children, and then repeat for each of those children — and when we get to leafs of the tree, execute a batch with markAsDelete/destroyPermanently for all of these. The point is to have a new method that automatically deletes the whole tree — so that the user doesn’t have to manually override the delete methods
  • Step 3: Improve the above’s performance, so that instead of calling fetch() on each child’d children collection (e.g. when deleting a Blog, we don’t fetch each post’s comment collection), we collect all child IDs and make a query to fetch all records of a given type all at once (e.g. we fetch blog’s posts, and then we fetch all comments whose post_id is one of the ids of posts we fetched)
  • Step 4: Continue improving performance by not actually fetching the whole children tree, but only fetching their IDs, and making sure to check collections’ caches to delete from JS the records that are already cached.
  • Step 5: Improve API: deprecate old methods, rename new methods, consider having a single delete({ permanently: boolean }) method, consider adding an association flag to skip deleting certain children, consider adding a supportsFastDelete = false Model flag if necessary, etc.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
stale[bot]commented, Feb 6, 2020

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

1reaction
radexcommented, Aug 9, 2019

@sd1998 Absolutely!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Delete Millions of Rows Fast with SQL
Removing all the rows fast with truncate; Using create-table-as-select to wipe a large fraction of the data; Dropping or truncating partitions ...
Read more >
How to delete blank cells and move data left in Excel?
To delete blank cells and move left, you just need to select all blank cells and delete them then shift right. 1. Select...
Read more >
How to Delete Just Some Rows from a Really Big Table
Deleting ALL of them is fast and easy – just do TRUNCATE TABLE – but things get much harder when you need to...
Read more >
Newsletter #47 - Google launch new AI drug discovery company ...
Our aim is to make sure that you are always up to date with the most important developments in this fast-moving field. Packed...
Read more >
How to Move Delete and Rename Locked Files
Search Close GO Software & Apps > Windows How to Move, Delete, and Rename Locked Files Getting a 'locked file' error? Here's what...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found