Roll-forward "Add preliminary support for persisting pre-saved history entries remotely"

This rolls-forward commit 66916c27cb.
This commit is contained in:
David Dworken
2023-09-22 13:13:46 -07:00
parent dc166ec089
commit 2a5a6d65c4
8 changed files with 76 additions and 42 deletions

View File

@ -152,7 +152,14 @@ func (db *DB) DumpRequestDeleteForUserAndDevice(ctx context.Context, userID, dev
func (db *DB) ApplyDeletionRequestsToBackend(ctx context.Context, request *shared.DeletionRequest) (int64, error) {
tx := db.WithContext(ctx).Where("false")
for _, message := range request.Messages.Ids {
tx = tx.Or(db.WithContext(ctx).Where("user_id = ? AND device_id = ? AND date = ?", request.UserId, message.DeviceId, message.Date))
// Note that this won't do server-side deletion of pre-saved history entries. This is an inherent
// limitation of our current DB schema. This is sub-par, since it means that even after deletion, clients
// may still receive deleted history entries. But, a well-behaved client will immediately delete
// these (never writing them to disk) and mark them as received, so this won't happen again.
//
// TODO: This could be improved upon if we added a HistoryEntry.EntryId field, backfilled it, added
// it to EncHistoryEntry, and then used that as a key for deletion.
tx = tx.Or(db.WithContext(ctx).Where("user_id = ? AND device_id = ? AND date = ?", request.UserId, message.DeviceId, message.EndTime))
}
result := tx.Delete(&shared.EncHistoryEntry{})
if tx.Error != nil {
@ -226,7 +233,7 @@ func (db *DB) Clean(ctx context.Context) error {
if r.Error != nil {
return r.Error
}
r = db.WithContext(ctx).Exec("DELETE FROM deletion_requests WHERE read_count > 100")
r = db.WithContext(ctx).Exec("DELETE FROM deletion_requests WHERE read_count > 1000")
if r.Error != nil {
return r.Error
}