1
votes

Almost all applications need to mark as delete some entities in the datastore. Depending on the business logic, these entities can be physically deleted, or just 'soft deleted' as described.

An obvious way to go with this in google datastore is having an indexed property which stores the soft delete information. For example:

Post
  - Title
  - Body
  - IsDeleted

The problem with this method is that, in order to keep track of a very small number of soft deleted entities, all of them must put up with the overhead of an extra index.

What are some strategies to avoid the index when the soft deleted entities are very small?

One approach I can think of is to change the entity kind, say from Post to DeletedPost, which involves physically deleting the old entity and creating a new one.

2

2 Answers

0
votes

The only other solution I could think of, is to create a table called DeletedPost, and just store the ID of the deleted posts in the table.

When doing your queries, exclude IDs in the deleted table. (join) So basically the same thing as adding IsDeleted, but moved to another table.

0
votes

It should be also possible to create a new namespace with suffix like __deleted but with the same kind and copying the entity to new namespace but with another Id to break index. So, it will allow you restore the entity in exactly in the same way, when it's really needed.