mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-09 23:17:55 +02:00
Roll-forward "Add preliminary support for persisting pre-saved history entries remotely"
This rolls-forward commit 66916c27cb
.
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user