there are two collections
data stores data, and
attach stores attachments
data and attach, one-to-many relationships.
the ratio of data to attach is about 1:10, that is, a piece of data data, and there may be 10-50 pieces of data below.
when data is tens of millions, attach may be hundreds of millions.
the problem now is that if the user deletes the data, then the attach must be deleted accordingly.
manipulating hundreds of millions of pieces of data is a long process. The database is also under a lot of pressure.
so consider whether it can be soft deleted, first set the data update status to delete, and ignore attach. Then use the program to clear it in the background in the later stage.
after all, the waiting time for updating tens of millions of data is not long.
but there is a problem. Attach needs to do data statistics. For example, before the user deletes, he calculates that his attachment occupies 20g of space, and after deletion, you have to give him the amount of attachment after deletion, otherwise the billing is not accurate.
so how to solve this problem?